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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ef042d05aeab5b8c0b04b20bc7d941cb12662f2
4
- data.tar.gz: 9db5f0ee408e17c7f6a25d1e1131f908af75ad9d
3
+ metadata.gz: c697de02d12f82cff623f3c5b32529e4e3f98507
4
+ data.tar.gz: 93872db6a95f5070a74a05c237b3123307616513
5
5
  SHA512:
6
- metadata.gz: ee52c72f005d0debe8829fe4ddbf659fdbc11f4850c4ac08811c84b8c52fdb6684ea73fb09ead5283ca90d1a29d7b031006a9c160815a0904ae42f2948ce0ba7
7
- data.tar.gz: e636aec70a610a459cce4c397e5a6d5c73240aef3cd6d05877d47b9e2785a4b8802d9acd1380538c44a513c14ac7a3f9d187c79ae2fb0c274c10e308799af94f
6
+ metadata.gz: f30e70813a4ba74f99b930e9854768ed1d3c0545d32d2fcccb33f5334e3da8f5740445362a0b47f65973dcc2d9cb8b207019926673e4b935df83be6d69d0af08
7
+ data.tar.gz: 47846145224e929adf014e08b6d5641fceeb9e371144f2d8793c07e7ffb3494e1e63c52921a4949f0f51e3816fccdc0883e5623d570d2d09ebc29b63853f379f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joumae (0.2.2)
4
+ joumae (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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(api_endpoint: api_endpoint || ENV['JOUMAE_API_ENDPOINT'], api_key: api_key || ENV['JOUMAE_API_KEY'])
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
- post_json(acquire_resource_url(name), {api_key: api_key})
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
- post_json(renew_resource_url(name), {api_key: api_key})
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)
@@ -61,6 +61,7 @@ module Joumae
61
61
  data = f.read_nonblock(1024)
62
62
 
63
63
  mapping[f].write(data)
64
+ mapping[f].flush
64
65
  rescue EOFError => e
65
66
  debug e.to_s;
66
67
  end
@@ -1,14 +1,15 @@
1
1
  module Joumae
2
2
  class Transaction
3
- def initialize(resource_name:, client:, renew_interval: 1)
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
- sleep @renew_interval
22
- @thread.exit if finished?
23
- @client.renew(@resource_name)
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
@@ -1,3 +1,3 @@
1
1
  module Joumae
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joumae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke KUOKA