consul-template-generator 0.1.0 → 0.1.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: ba8f1717006ac33f420edd8b83719bdb68aae412
4
- data.tar.gz: c0069022ebf8e26f26565428d15d7d553b791169
3
+ metadata.gz: 8be4b2612c0cdde3c4ddc78e08af58fddae3fb12
4
+ data.tar.gz: 594615f00d8f7f8ee0c97923d78666b600fd8755
5
5
  SHA512:
6
- metadata.gz: 63b020316a8f3291225f0ecc82e95e9ecd60b0a99205ecad5c5e8089c6c19c457422a292959fb724ee38dc60a9e1aea4e4b6b21924fe3fd2cb41fa1495ac29ae
7
- data.tar.gz: 05eec4beb3cd09c1135ae92c59ded085fb678adec808ce483ff38f0fe35ead70510f439713c64a6e5bf0ebce7856ad205b2f7ed4e751cb17ba313b657bc0e6b4
6
+ metadata.gz: c7aeee64cbdfe213d140a5f2a3c13d2cbfed1988a5e4bcf8fb1522abfc5ae68f755cde2156bafa5a6d8c3baef426f419b58f989562dce00b618a61e688e20396
7
+ data.tar.gz: e449b39989b443d9f19a0f1405658c50ed96163cfc1fcf271a151e3dc0841d4ccb0256204768286e50f3a01d9a37daffd7c583b351b15077842b6506a123752b
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.2.0
6
+ bundler_args: --binstubs
7
+ script: "bin/rspec --format doc"
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ [![Build Status](https://travis-ci.org/socrata-platform/consul-template-generator.svg)](https://travis-ci.org/socrata-platform/consul-template-generator)
2
+
3
+ # TODO
@@ -50,6 +50,16 @@ EOC
50
50
  opts.on('-l LOG_LEVEL', '--log-level LOG_LEVEL', "Log level, options are 'debug', 'info', 'error' [default: info]") do |l|
51
51
  options[:log_level] = l.to_sym
52
52
  end
53
+
54
+ options[:cycle_sleep] = 0.5
55
+ opts.on(nil, '--cycle-sleep CYCLE_SLEEP', "Sleep interval in seconds between each template rendering [default: 0.5]") do |s|
56
+ options[:cycle_sleep] = s.to_f
57
+ end
58
+
59
+ options[:lock_sleep] = 1.0
60
+ opts.on(nil, '--lock-sleep LOCK_SLEEP', "Sleep interval in seconds between each attempt to obtain a session lock [default: 1.0]") do |s|
61
+ options[:cycle_sleep] = s.to_f
62
+ end
53
63
  end
54
64
 
55
65
  opt_parser.parse!
@@ -70,7 +80,7 @@ ec = 1
70
80
  cmd = ARGV[0]
71
81
  case cmd
72
82
  when 'run'
73
- ec = CMD.run
83
+ ec = CMD.run(options[:cycle_sleep], options[:lock_sleep])
74
84
  when 'once'
75
85
  ec = CMD.run_once
76
86
  else
@@ -15,7 +15,9 @@ module Consul
15
15
  end
16
16
  end
17
17
 
18
- def self.run
18
+ def self.run(cycle_sleep = nil, lock_sleep = nil)
19
+ cycle_sleep ||= 0.5
20
+ lock_sleep ||= 1.0
19
21
  config = Consul::Template::Generator.config
20
22
  uploaded_hash = nil
21
23
  begin
@@ -24,7 +26,7 @@ module Consul
24
26
  config.logger.info "Session lock acquired..."
25
27
  begin
26
28
  uploaded_hash = runner.run(uploaded_hash) || uploaded_hash
27
- sleep 5
29
+ sleep cycle_sleep
28
30
  rescue Interrupt
29
31
  raise # Re-raise to break this rescue block
30
32
  rescue ConsulSessionExpired
@@ -33,20 +35,20 @@ module Consul
33
35
  rescue Exception => e
34
36
  config.logger.error "An error occurred while updating template: #{e.message}"
35
37
  config.logger.debug "Sleeping before attempting to update again..."
36
- sleep 5
38
+ sleep lock_sleep
37
39
  break
38
40
  end until false
39
41
  end
40
42
  rescue Interrupt
41
- config.logger.error "Recieved interrupt signal, exiting..."
43
+ config.logger.error "Received interrupt signal, exiting..."
42
44
  break
43
45
  rescue Exception => e
44
46
  config.logger.info "Unable to obtain session lock: #{e.message}"
45
47
  config.logger.debug "Sleeping before attempting lock session again..."
46
48
  begin
47
- sleep 5
49
+ sleep lock_sleep
48
50
  rescue Interrupt
49
- config.logger.error "Recieved interrupt signal, exiting..."
51
+ config.logger.error "Received interrupt signal, exiting..."
50
52
  break
51
53
  end
52
54
  end until false
@@ -1,7 +1,7 @@
1
1
  module Consul
2
2
  module Template
3
3
  module Generator
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
7
7
  end
data/spec/ct_spec.rb CHANGED
@@ -26,6 +26,7 @@ describe 'Consul::Template::Generator::CTRunner' '#render_template' do
26
26
  Consul::Template::Generator.configure do |config|
27
27
  config.template = '/etc/test-template.ctmpl'
28
28
  config.template_key = '/test-template'
29
+ config.consul_template_binary = 'consul-template'
29
30
  end
30
31
  end
31
32
 
data/spec/init_spec.rb CHANGED
@@ -11,6 +11,7 @@ describe 'Consul::Template::Generator::CTRunner' '#initialize' do
11
11
  config.template = 'test-session-template.ctmpl'
12
12
  config.template_key = 'test-session-template'
13
13
  config.node = 'test-node'
14
+ config.consul_template_binary = 'consul-template'
14
15
  end
15
16
  end
16
17
 
@@ -13,12 +13,13 @@ describe 'Consul::Template::Generator::CTRunner' '#acquire_lock' do
13
13
  config.template = 'test-template.ctmpl'
14
14
  config.template_key = '/test-template'
15
15
  config.consul_host = '127.0.0.1:8500'
16
+ config.consul_template_binary = 'consul-template'
16
17
  config.log_level = :off
17
18
  end
18
19
  end
19
20
 
20
- context 'aquires lock' do
21
- it 'clean lock acquisision' do
21
+ context 'acquires lock' do
22
+ it 'clean lock acquisition' do
22
23
  runner = CTRunner.new('test-session')
23
24
  runner.acquire_lock do
24
25
  expect(true).to be_truthy ## This is simply to assert we are able to execute code in the block
@@ -42,12 +43,13 @@ describe 'Consul::Template::Generator::CTRunner' '#acquire_session_lock' do
42
43
  config.template = 'test-template.ctmpl'
43
44
  config.template_key = '/test-template'
44
45
  config.consul_host = '127.0.0.1:8500'
46
+ config.consul_template_binary = 'consul-template'
45
47
  config.log_level = :off
46
48
  end
47
49
  end
48
50
 
49
- context 'aquires session lock' do
50
- it 'clean lock acquisision' do
51
+ context 'acquires session lock' do
52
+ it 'clean lock acquisition' do
51
53
  runner = CTRunner.new('test-session')
52
54
  runner.acquire_session_lock do
53
55
  expect(true).to be_truthy ## This is simply to assert we are able to execute code in the block
@@ -72,6 +74,7 @@ describe 'Consul::Template::Generator::CTRunner' '#upload_template' do
72
74
  config.template = 'test-template.ctmpl'
73
75
  config.template_key = '/test-template'
74
76
  config.consul_host = '127.0.0.1:8500'
77
+ config.consul_template_binary = 'consul-template'
75
78
  config.log_level = :off
76
79
  end
77
80
  end
@@ -90,6 +93,7 @@ describe 'Consul::Template::Generator::CTRunner' '#upload_template' do
90
93
  config.template = 'test-template.ctmpl'
91
94
  config.template_key = '/test-template-failure'
92
95
  config.consul_host = '127.0.0.1:8500'
96
+ config.consul_template_binary = 'consul-template'
93
97
  config.log_level = :off
94
98
  end
95
99
  end
data/spec/run_spec.rb CHANGED
@@ -19,7 +19,7 @@ describe 'Consul::Template::Generator::CTRunner' '#run' do
19
19
  expect(hash).to eql(exp_hash)
20
20
  end
21
21
 
22
- it "does't upload unchanged template" do
22
+ it "doesn't upload unchanged template" do
23
23
  exp_hash = 'bbf9afe7431caf5f89a608bc31e8d822'
24
24
  expect(@runner).to receive(:render_template).with(no_args).and_return([0, 'test body', exp_hash])
25
25
  expect(@runner).not_to receive(:upload_template)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consul-template-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Oldfield
@@ -150,8 +150,10 @@ extra_rdoc_files: []
150
150
  files:
151
151
  - .gitignore
152
152
  - .rspec
153
+ - .travis.yml
153
154
  - Gemfile
154
155
  - Gemfile.lock
156
+ - README.md
155
157
  - bin/consul-template-generator
156
158
  - consul-template-generator.gemspec
157
159
  - lib/consul/template/generator.rb