joumae 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/joumae/client.rb +14 -7
- data/lib/joumae/command.rb +1 -0
- data/lib/joumae/transaction.rb +9 -5
- data/lib/joumae/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c697de02d12f82cff623f3c5b32529e4e3f98507
|
4
|
+
data.tar.gz: 93872db6a95f5070a74a05c237b3123307616513
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f30e70813a4ba74f99b930e9854768ed1d3c0545d32d2fcccb33f5334e3da8f5740445362a0b47f65973dcc2d9cb8b207019926673e4b935df83be6d69d0af08
|
7
|
+
data.tar.gz: 47846145224e929adf014e08b6d5641fceeb9e371144f2d8793c07e7ffb3494e1e63c52921a4949f0f51e3816fccdc0883e5623d570d2d09ebc29b63853f379f
|
data/Gemfile.lock
CHANGED
data/lib/joumae/client.rb
CHANGED
@@ -7,25 +7,32 @@ module Joumae
|
|
7
7
|
attr_reader :api_endpoint
|
8
8
|
attr_reader :api_key
|
9
9
|
|
10
|
-
def self.create(api_endpoint: nil, api_key: nil)
|
11
|
-
new(
|
10
|
+
def self.create(api_endpoint: nil, api_key: nil, ttl: 15)
|
11
|
+
new(
|
12
|
+
api_endpoint: api_endpoint || ENV['JOUMAE_API_ENDPOINT'],
|
13
|
+
api_key: api_key || ENV['JOUMAE_API_KEY'],
|
14
|
+
ttl: ttl
|
15
|
+
)
|
12
16
|
end
|
13
17
|
|
14
|
-
def initialize(api_endpoint:, api_key:)
|
18
|
+
def initialize(api_endpoint:, api_key:, ttl:)
|
15
19
|
@api_endpoint = api_endpoint
|
16
20
|
@api_key = api_key
|
21
|
+
@ttl = ttl
|
17
22
|
end
|
18
23
|
|
19
24
|
def create(name)
|
20
25
|
post_json(resources_url, {api_key: api_key, name: name})
|
21
26
|
end
|
22
27
|
|
23
|
-
def acquire(name)
|
24
|
-
|
28
|
+
def acquire(name, ttl: nil)
|
29
|
+
params = {api_key: api_key, ttl: ttl || @ttl}
|
30
|
+
post_json(acquire_resource_url(name), params)
|
25
31
|
end
|
26
32
|
|
27
|
-
def renew(name)
|
28
|
-
|
33
|
+
def renew(name, ttl: nil)
|
34
|
+
params = {api_key: api_key, ttl: ttl || @ttl}
|
35
|
+
post_json(renew_resource_url(name), params)
|
29
36
|
end
|
30
37
|
|
31
38
|
def release(name)
|
data/lib/joumae/command.rb
CHANGED
data/lib/joumae/transaction.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module Joumae
|
2
2
|
class Transaction
|
3
|
-
def initialize(resource_name:, client:, renew_interval:
|
3
|
+
def initialize(resource_name:, client:, renew_interval: 20, ttl: 30)
|
4
4
|
@resource_name = resource_name
|
5
5
|
@client = client
|
6
6
|
@renew_interval = renew_interval
|
7
|
+
@ttl = ttl
|
7
8
|
@finished = false
|
8
9
|
end
|
9
10
|
|
10
11
|
def start
|
11
|
-
@client.acquire(@resource_name)
|
12
|
+
@client.acquire(@resource_name, ttl: @ttl)
|
12
13
|
|
13
14
|
start_thread
|
14
15
|
end
|
@@ -18,9 +19,12 @@ module Joumae
|
|
18
19
|
|
19
20
|
@thread = Thread.start {
|
20
21
|
loop do
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
wait_started_time = Time.now
|
23
|
+
while Time.now - wait_started_time < @renew_interval
|
24
|
+
sleep 0.1
|
25
|
+
@thread.exit if finished?
|
26
|
+
end
|
27
|
+
@client.renew(@resource_name, ttl: @ttl)
|
24
28
|
end
|
25
29
|
}
|
26
30
|
end
|
data/lib/joumae/version.rb
CHANGED