Class: Adminix::Watcher
- Inherits:
-
Object
- Object
- Adminix::Watcher
- Defined in:
- lib/adminix/watcher.rb
Constant Summary collapse
- DEFAULT_PERIOD =
5
Instance Attribute Summary collapse
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts) ⇒ Watcher
constructor
A new instance of Watcher.
- #run! ⇒ Object
- #sync_service ⇒ Object
- #trap_signal ⇒ Object
Constructor Details
#initialize(opts) ⇒ Watcher
Returns a new instance of Watcher.
13 14 15 16 |
# File 'lib/adminix/watcher.rb', line 13 def initialize(opts) @period = opts[:period] || DEFAULT_PERIOD @service = Service.instance end |
Instance Attribute Details
#period ⇒ Object (readonly)
Returns the value of attribute period.
11 12 13 |
# File 'lib/adminix/watcher.rb', line 11 def period @period end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
11 12 13 |
# File 'lib/adminix/watcher.rb', line 11 def service @service end |
Class Method Details
Instance Method Details
#run! ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/adminix/watcher.rb', line 18 def run! trap_signal EventMachine.run do EventMachine.add_periodic_timer(period) do sync_service end end end |
#sync_service ⇒ Object
28 29 30 31 32 |
# File 'lib/adminix/watcher.rb', line 28 def sync_service puts "Syncing service" #puts @service.run_cmd('whoami') service.sync end |
#trap_signal ⇒ Object
34 35 36 37 38 39 |
# File 'lib/adminix/watcher.rb', line 34 def trap_signal Signal.trap("SIGINT") do puts "Stopping..." EventMachine.stop end end |