Class: PushyClient::PeriodicReconfigurer
- Inherits:
-
Object
- Object
- PushyClient::PeriodicReconfigurer
- Defined in:
- lib/pushy_client/periodic_reconfigurer.rb
Constant Summary collapse
- SPLAY =
0.10
- POLL_INTERVAL =
seconds
5
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
- #reconfigure_deadline ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
-
#update_reconfigure_deadline(delay) ⇒ Object
set the reconfigure deadline to some future number of seconds (with a splay applied).
Constructor Details
#initialize(client) ⇒ PeriodicReconfigurer
Returns a new instance of PeriodicReconfigurer.
23 24 25 26 27 28 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 23 def initialize(client) @prng = Random.new @client = client @lock = Mutex.new @reconfigure_deadline = nil end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
30 31 32 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 30 def client @client end |
#lifetime ⇒ Object (readonly)
Returns the value of attribute lifetime.
31 32 33 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 31 def lifetime @lifetime end |
Instance Method Details
#node_name ⇒ Object
33 34 35 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 33 def node_name client.node_name end |
#reconfigure ⇒ Object
80 81 82 83 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 80 def reconfigure stop start end |
#reconfigure_deadline ⇒ Object
37 38 39 40 41 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 37 def reconfigure_deadline @lock.synchronize do @reconfigure_deadline end end |
#start ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 51 def start @lifetime = client.config['lifetime'] @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 update_reconfigure_deadline(@lifetime) while Time.now < reconfigure_deadline do # could also check the config file for updates here and # resolve a long standing wishlist item from customers. sleep(POLL_INTERVAL) end Chef::Log.info "[#{node_name}] Reconfigure deadline of #{reconfigure_deadline} is now past. Reconfiguring / reloading keys ..." client.trigger_reconfigure rescue client.log_exception("Error in reconfigure thread", $!) end end end end |
#stop ⇒ Object
73 74 75 76 77 78 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 73 def stop Chef::Log.info "[#{node_name}] Stopping reconfigure thread ..." @reconfigure_thread.kill @reconfigure_thread.join @reconfigure_thread = nil end |
#update_reconfigure_deadline(delay) ⇒ Object
set the reconfigure deadline to some future number of seconds (with a splay applied)
44 45 46 47 48 49 |
# File 'lib/pushy_client/periodic_reconfigurer.rb', line 44 def update_reconfigure_deadline(delay) @lock.synchronize do @reconfigure_deadline = Time.now + delay * (1 - @prng.rand(SPLAY)) Chef::Log.info "[#{node_name}] Setting reconfigure deadline to #{@reconfigure_deadline}" end end |