consul-template-generator 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c81f7c798493e55d5de09e72f18774969babccb2
4
- data.tar.gz: c8b6ed3a09773848a3c02cd4d97edc1d65c8dfbe
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODY5MTY5NmE1MWZjZTUxZDNmYWQ0NjA5M2FjYjEzNzU1NTBiMTM4OA==
5
+ data.tar.gz: !binary |-
6
+ YTFmNGE4OWRjNDQ5MDgyOTAyY2QwOTU4MTg2ZmNiM2IxMjg5NjE3Ng==
5
7
  SHA512:
6
- metadata.gz: 0c687b4a6fcc7414422484a01083ef65e9f592a0ba55950df4332d56bd9accdd689b62d23f6fbc2069f908a49580925b2440027bd9262ac7f521dbf3dfac5da3
7
- data.tar.gz: a30164de62fbaac82dfd7715003fc2db6a5ed1bd8b351e7b31a9aee6ab2569477c05065eede82609914a48cc1e4bdab4523bc2d2f5775abce22b19434aebc352
8
+ metadata.gz: !binary |-
9
+ ZTFjMDM4ZDc3OTU5NmQ3ZDIyNGQ1ODMyZjY5OGQxYmYwMmM0NzMwODdmMjQw
10
+ MzUxOTNlMDdkMDAxODJhYjg2MTVlMTgzMDFhMTgyYTcwZWRkMjQ2MGU3MWNm
11
+ ZTkwZTJkYWQ5NTJlZGQ1ZmU3MzY5ZGM3NzY1NDIxYzY0MjBlOTE=
12
+ data.tar.gz: !binary |-
13
+ NjY0NTliM2E5NDVkZTIzZTZjZjJhNjkzZGQ0ZGIwYTk2ZWZiNDU3ZGQwODM2
14
+ ZGI3MGYwYWMzZDZmMDlkNWZiOGJjZjc2MmE1NzY1NTdhNmRjNmY5OTVkMzcy
15
+ NTA5NjI4MjZmMjRlZWI3OGFkMTI0MzI4Mjk5YTRmNzEzMDBiYmM=
@@ -59,7 +59,7 @@ module Consul
59
59
  end
60
60
 
61
61
  def destroy_session(sess_id)
62
- Diplomat::Session.destroy sess_id
62
+ 'true' == Diplomat::Session.destroy(sess_id)
63
63
  end
64
64
  end
65
65
  end
@@ -17,7 +17,7 @@ module Consul
17
17
  @config = Consul::Template::Generator.config
18
18
  end
19
19
 
20
- def signals
20
+ def configure_signal_handlers
21
21
  Signal.trap("INT") do
22
22
  @config.logger.error "Received INT signal..."
23
23
  @interrupted = true
@@ -30,7 +30,7 @@ module Consul
30
30
  end
31
31
 
32
32
  def run(cycle_sleep = nil, lock_sleep = nil)
33
- signals
33
+ configure_signal_handlers
34
34
  @terminated = false
35
35
  cycle_sleep ||= 0.5
36
36
  lock_sleep ||= 1.0
@@ -59,6 +59,10 @@ module Consul
59
59
  def session_lock_key
60
60
  @session_key
61
61
  end
62
+
63
+ def session_name
64
+ @session_key.split('/')[-1]
65
+ end
62
66
  end
63
67
  end
64
68
  end
@@ -5,28 +5,34 @@ module Consul
5
5
  attr_accessor :session
6
6
 
7
7
  def initialize(consul_session_id = nil, do_create_session = true)
8
+ @config = Consul::Template::Generator.config
8
9
  if (consul_session_id.nil? && do_create_session)
9
10
  create_session
10
11
  else
11
12
  @session = consul_session_id
12
13
  end
13
- @config = Consul::Template::Generator.config
14
14
  end
15
15
 
16
16
  def create_session
17
17
  unless @session.nil?
18
18
  destroy_session
19
19
  end
20
- @session = Consul::Template::Generator.create_session 'consul-template-generator'
20
+ @session = Consul::Template::Generator.create_session @config.session_name
21
21
  end
22
22
 
23
23
  def destroy_session
24
+ attempts = 0
24
25
  begin
25
- Consul::Template::Generator.destroy_session @session
26
+ destroyed = Consul::Template::Generator.destroy_session @session
26
27
  rescue
27
- Consul::Template::Generator.config.logger.info "Failed to destroy session: #{@session}"
28
- end
29
- @session = nil
28
+ Consul::Template::Generator.config.logger.info "Failed to destroy session: #{@session}, attempt number #{attempts}"
29
+ ensure
30
+ @session = destroyed ? nil : @session
31
+ unless @session.nil?
32
+ attempts += 1
33
+ sleep 0.25
34
+ end
35
+ end until (destroyed || attempts > 4)
30
36
  end
31
37
  end
32
38
  end
@@ -1,7 +1,7 @@
1
1
  module Consul
2
2
  module Template
3
3
  module Generator
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
6
6
  end
7
7
  end
@@ -11,6 +11,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
11
11
  config.templates = {'test-session-template.ctmpl' => 'test-session-template' }
12
12
  config.node = 'test-node'
13
13
  config.log_level = :off
14
+ config.session_key = '/session/consul-template-generator'
14
15
  config.consul_template_binary = 'consul-template'
15
16
  end
16
17
  end
@@ -41,7 +42,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
41
42
  expect(runner.session).to eql('failed-destroyed-session')
42
43
  runner.create_session
43
44
  expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/create').with(:body => '{"Node":"test-node","Name":"consul-template-generator","Behavior":"release"}')
44
- expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/failed-destroyed-session')
45
+ expect(WebMock).to have_requested(:put, 'http://127.0.0.1:8500/v1/session/destroy/failed-destroyed-session').times(5)
45
46
  expect(runner.session).to eql('test-session-id')
46
47
  end
47
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consul-template-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Oldfield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -180,12 +180,12 @@ require_paths:
180
180
  - lib
181
181
  required_ruby_version: !ruby/object:Gem::Requirement
182
182
  requirements:
183
- - - '>='
183
+ - - ! '>='
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  requirements:
188
- - - '>='
188
+ - - ! '>='
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
@@ -201,4 +201,3 @@ test_files:
201
201
  - spec/key_value_spec.rb
202
202
  - spec/run_spec.rb
203
203
  - spec/spec_helper.rb
204
- has_rdoc: