Module: Consul::Template::Generator::CMD
- Includes:
- Consul::Template::Generator
- Defined in:
- lib/consul/template/generator/cmd.rb
Constant Summary
Constants included from Consul::Template::Generator
Class Method Summary collapse
- .configure(consul_host, templates, session_key, log_level, proxy = nil) ⇒ Object
- .run(cycle_sleep = nil, lock_sleep = nil) ⇒ Object
- .run_once ⇒ Object
Class Method Details
.configure(consul_host, templates, session_key, log_level, proxy = nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/consul/template/generator/cmd.rb', line 9 def self.configure(consul_host, templates, session_key, log_level, proxy = nil) Consul::Template::Generator.configure do |config| config.log_level = log_level config.templates = templates config.session_key = session_key config.consul_host = consul_host end end |
.run(cycle_sleep = nil, lock_sleep = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/consul/template/generator/cmd.rb', line 18 def self.run(cycle_sleep = nil, lock_sleep = nil) cycle_sleep ||= 0.5 lock_sleep ||= 1.0 config = Consul::Template::Generator.config uploaded_hashes = {} begin runner = CTRunner.new runner.acquire_session_lock do config.logger.info "Session lock acquired..." begin config.templates.each do |template,template_key| uploaded_hashes[template] = runner.run(template, template_key, uploaded_hashes[template]) || uploaded_hashes[template] sleep cycle_sleep end rescue Interrupt raise # Re-raise to break this rescue block rescue ConsulSessionExpired config.logger.error "The current consul session has expired." break rescue Exception => e config.logger.error "An error occurred while updating template: #{e.}" config.logger.debug "Sleeping before attempting to update again..." sleep lock_sleep break end until false end rescue Interrupt config.logger.error "Received interrupt signal, exiting..." break rescue Exception => e config.logger.info "Unable to obtain session lock: #{e.}" config.logger.debug "Sleeping before attempting lock session again..." begin sleep lock_sleep rescue Interrupt config.logger.error "Received interrupt signal, exiting..." break end ensure runner.destroy_session end until false 0 end |
.run_once ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/consul/template/generator/cmd.rb', line 62 def self.run_once config = Consul::Template::Generator.config begin config.templates.each do |template,template_key| runner = CTRunner.new result = runner.run template, template_key end rescue Exception => e config.logger.error "An unexpected error occurred, unable to process template: #{e.}" 1 else 0 end end |