Class: PushyClient::PeriodicReconfigurer
- Inherits:
-
Object
- Object
- PushyClient::PeriodicReconfigurer
- Defined in:
- lib/pushy_client/periodic_reconfigurer.rb
Constant Summary collapse
- SPLAY =
0.10
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#lifetime ⇒ Object
readonly
Returns the value of attribute lifetime.
Instance Method Summary collapse
-
#initialize(client) ⇒ PeriodicReconfigurer
constructor
A new instance of PeriodicReconfigurer.
- #node_name ⇒ Object
- #reconfigure ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(client) ⇒ PeriodicReconfigurer
Returns a new instance of PeriodicReconfigurer.
21 22 23 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 21 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
25 26 27 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 25 def client @client end |
#lifetime ⇒ Object (readonly)
Returns the value of attribute lifetime.
26 27 28 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 26 def lifetime @lifetime end |
Instance Method Details
#node_name ⇒ Object
28 29 30 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 28 def node_name client.node_name end |
#reconfigure ⇒ Object
57 58 59 60 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 57 def reconfigure stop start end |
#start ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 32 def start @lifetime = client.config['lifetime'] prng = Random.new @reconfigure_thread = Thread.new do Chef::Log.info "[#{node_name}] Starting reconfigure thread. Will reconfigure / reload keys after #{@lifetime} seconds, less up to splay #{SPLAY}." while true begin @delay = @lifetime * (1 - prng.rand(SPLAY)) sleep(@delay) Chef::Log.info "[#{node_name}] Config is now #{@delay} seconds old. Reconfiguring / reloading keys ..." client.trigger_reconfigure rescue client.log_exception("Error in reconfigure thread", $!) end end end end |
#stop ⇒ Object
50 51 52 53 54 55 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 50 def stop Chef::Log.info "[#{node_name}] Stopping reconfigure thread ..." @reconfigure_thread.kill @reconfigure_thread.join @reconfigure_thread = nil end |