diplomat 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c7efb343599818bf0533dcb8695aa0283ab59aa
4
- data.tar.gz: 000d4c18b30c36c3739ad0d1deda567eebe00cb2
3
+ metadata.gz: 3f1c9c12e4e39b571bceb79ece16ea11b65e86a1
4
+ data.tar.gz: 20aab29fd76ec1ccca03f7051a2055d90e2e7c47
5
5
  SHA512:
6
- metadata.gz: f6aaea91e904df541b9f5a275e2450072411a488522c8748705a826f8d0725ac15c1c2d6d16cb9c037e963853801eb25ff4bf70363bf56dbf9d97069c0ac76b4
7
- data.tar.gz: f2e2c8d09390bb45c9fbd4f3779516edefb8921962e3a7f01944c7fbd1037be738bde86d0bdef3d4262c79c52b7a46ad80ccca25ebe42d5ab66a2d8183a0b3f5
6
+ metadata.gz: 90217e6d23c9fa287a1d53a0e6d9d4abb7e2700222f232b397e154004994880160a0ca97ae27019ba0811f2e054d190d61542a20292fa7c670ed9feeb847e7e8
7
+ data.tar.gz: 9666756e0d00d492342a4f5898885d459724c8fdbfe5fc36754abcab80fa11faa1a9d4819191183b96a94fff4ae3fa5630fc05708ff58dca12bb0eea31336280
data/README.md CHANGED
@@ -87,7 +87,7 @@ foo_service = Diplomat::Service.get('foo', :all)
87
87
  Creating a session:
88
88
 
89
89
  ```ruby
90
- sessionid = Diplomat::Session.create({:hostname => "server1", :ipaddress => "4.4.4.4"})
90
+ sessionid = Diplomat::Session.create({:Node => "server1", :Name => "my-lock"})
91
91
  # => "fc5ca01a-c317-39ea-05e8-221da00d3a12"
92
92
  ```
93
93
  Or destroying a session:
@@ -101,7 +101,7 @@ Diplomat::Session.destroy("fc5ca01a-c317-39ea-05e8-221da00d3a12")
101
101
  Acquire a lock:
102
102
 
103
103
  ```ruby
104
- sessionid = Diplomat::Session.create({:hostname => "server1", :ipaddress => "4.4.4.4"})
104
+ sessionid = Diplomat::Session.create({:Node => "server1", :Name => "my-lock"})
105
105
  lock_acquired = Diplomat::Lock.acquire("/key/to/lock", sessionid)
106
106
  # => true
107
107
  ```
data/lib/diplomat/lock.rb CHANGED
@@ -6,25 +6,26 @@ module Diplomat
6
6
  # Acquire a lock
7
7
  # @param key [String] the key
8
8
  # @param session [String] the session, generated from Diplomat::Session.create
9
+ # @param value [String] the value for the key
9
10
  # @return [Boolean] If the lock was acquired
10
- def acquire key, session
11
+ def acquire key, session, value=nil
11
12
  raw = @conn.put do |req|
12
13
  req.url "/v1/kv/#{key}?acquire=#{session}"
14
+ req.body = value unless value.nil?
13
15
  end
14
- return true if raw.body == 'true'
15
- return false
16
-
16
+ raw.body == 'true'
17
17
  end
18
18
 
19
19
  # wait to aquire a lock
20
20
  # @param key [String] the key
21
21
  # @param session [String] the session, generated from Diplomat::Session.create
22
+ # @param value [String] the value for the key
22
23
  # @param check_interval [Integer] number of seconds to wait between retries
23
24
  # @return [Boolean] If the lock was acquired
24
- def wait_to_acquire key, session, check_interval=10
25
+ def wait_to_acquire key, session, value=nil, check_interval=10
25
26
  acquired = false
26
27
  while !acquired
27
- acquired = self.acquire key, session
28
+ acquired = self.acquire key, session, value
28
29
  sleep(check_interval) if !acquired
29
30
  return true if acquired
30
31
  end
@@ -4,12 +4,14 @@ module Diplomat
4
4
  class Session < Diplomat::RestClient
5
5
 
6
6
  # Create a new session
7
- # @param value [String] json representation of the local node
7
+ # @param value [Object] hash or json representation of the session arguments
8
8
  # @return [String] The sesssion id
9
- def create value
9
+ def create value=nil
10
+ # TODO: only certain keys are recognised in a session create request,
11
+ # should raise an error on others.
10
12
  raw = @conn.put do |req|
11
13
  req.url "/v1/session/create"
12
- req.body = value
14
+ req.body = (if value.kind_of?(String) then value else JSON.generate(value) end) unless value.nil?
13
15
  end
14
16
  body = JSON.parse(raw.body)
15
17
  return body["ID"]
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink