README.md in lusnoc-0.1.0 vs README.md in lusnoc-0.1.2.16548
- old
+ new
@@ -1,8 +1,17 @@
# Lusnoc
-Lusnoc is reliable gem to deal with [Consul](https://www.consul.io). It is designed to be simple and without any background magic.
+[![Gem Version](https://badge.fury.io/rb/lusnoc.svg)](https://rubygems.org/gems/lusnoc)
+[![Gem](https://img.shields.io/gem/dt/lusnoc.svg)](https://rubygems.org/gems/lusnoc/versions)
+
+[![Test Coverage](https://api.codeclimate.com/v1/badges/ed48b89a9793a074cd23/test_coverage)](https://codeclimate.com/github/RnD-Soft/lusnoc/test_coverage)
+[![Maintainability](https://api.codeclimate.com/v1/badges/ed48b89a9793a074cd23/maintainability)](https://codeclimate.com/github/RnD-Soft/lusnoc/maintainability)
+[![Quality](https://lysander.x.rnds.pro/api/v1/badges/lusnoc_quality.svg)](https://lysander.x.rnds.pro/api/v1/badges/lusnoc_quality.html)
+[![Outdated](https://lysander.x.rnds.pro/api/v1/badges/lusnoc_outdated.svg)](https://lysander.x.rnds.pro/api/v1/badges/lusnoc_outdated.html)
+[![Vulnerabilities](https://lysander.x.rnds.pro/api/v1/badges/lusnoc_vulnerable.svg)](https://lysander.x.rnds.pro/api/v1/badges/lusnoc_vulnerable.html)
+
+Lusnoc is reliable gem to deal with [Consul](https://www.consul.io). It is designed to be simple and work without dark background magic.
It is inspired by [consul-mutex](https://github.com/discourse/consul-mutex)(which has hard background magic).
## FAQ
#### What's Lusnoc for?
@@ -11,24 +20,24 @@
#### What's the difference between lusnoc and [consul-mutex](https://github.com/discourse/consul-mutex) or [diplomat](https://github.com/WeAreFarmGeek/diplomat)
* consul-mutex starts background thread and ***the block of code that you pass to #synchronize runs on a separate thread, and can be killed without warning if the mutex determines that it no longer holds the lock.***
* diplomat provides the basic session/locks functionality but no automated control over it
-#### How luscon deal with sessions/mutexes?
-* Luscon ensures session creation/destruction upon block execution
-* Luscon uses only sessions with TTL to protect you system from stale sessions/locks
-* Luscon enforces you to manualy renew session(through callback or explicit check) but provide background session checker
-* Luscon tries to carefuly handle timeouts and expiration using Consul [blocking queries](https://www.consul.io/api/features/blocking.html)
+#### How Lusnoc deal with sessions/mutexes?
+* Lusnoc ensures session creation/destruction upon block execution
+* Lusnoc uses only sessions with TTL to protect you system from stale sessions/locks
+* Lusnoc enforces you to manualy renew session(through callback or explicit check) but provide background session checker
+* Lusnoc tries to carefuly handle timeouts and expiration using Consul [blocking queries](https://www.consul.io/api/features/blocking.html)
# Usage
-Simply instantiate a new `Luscon::Mutex`, giving it the key you want to use
+Simply instantiate a new `Lusnoc::Mutex`, giving it the key you want to use
as the "lock":
```ruby
- require 'luscon/mutex'
- mutex = Luscon::Mutex.new('/locks/mx1', ttl: 20)
+ require 'lusnoc/mutex'
+ mutex = Lusnoc::Mutex.new('/locks/mx1', ttl: 20)
```
TTL will be used in session creation on `#synchronize`:
```ruby
mutex.synchronize(timeout: 10) do |mx|
puts "We are exclusively owns resource"
@@ -37,17 +46,17 @@
If mutex cannot be acquired within given timeout Lusnoc::TimeoutError is raised.
By default, the "value" of the lock resource will be the hostname of the
machine that it's running on (so you know who has the lock). If, for some
reason, you'd like to set the value to something else, you can do that, too:
```ruby
- Luscon::Mutex.new('/some/key', value: {time: Time.now}).synchronize do |mx|
+ Lusnoc::Mutex.new('/some/key', value: {time: Time.now}).synchronize do |mx|
#...
end
```
-Session invalidation/renewval handled through mutex instance:
+Session invalidation/renewal handled through mutex instance:
```ruby
- Luscon::Mutex.new('/some/key').synchronize do |mx|
+ Lusnoc::Mutex.new('/some/key').synchronize do |mx|
mx.time_to_expiration # seconds to session expiration in consul.
mx.ttl # session ttl.
mx.need_renew? # true when time_to_expiration less than half of ttl
mx.need_renew? # false
@@ -82,16 +91,28 @@
end
```
Typical usage scenario:
```ruby
- Luscon::Mutex.new('/some/key').synchronize do |mx|
+ Lusnoc::Mutex.new('/some/key').synchronize do |mx|
# do some work
mx.renew if mx.need_renew?
# do other work
mx.renew if mx.need_renew?
# ...
rescue Lusnoc::ExpiredError => e
# Session was invalidated and mutex was lost!
end
```
+
+# Installation
+
+It's a gem:
+```bash
+ gem install lusnoc
+```
+There's also the wonders of [the Gemfile](http://bundler.io):
+```ruby
+ gem 'lusnoc'
+```
+