Class: InboxSync::Runner
- Inherits:
-
Object
- Object
- InboxSync::Runner
- Defined in:
- lib/inbox-sync/runner.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#syncs ⇒ Object
readonly
Returns the value of attribute syncs.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Runner
constructor
A new instance of Runner.
- #shutdown? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(*args) ⇒ Runner
Returns a new instance of Runner.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/inbox-sync/runner.rb', line 9 def initialize(*args) opts, syncs = [ args.last.kind_of?(Hash) ? args.pop : {}, args.flatten ] @syncs = syncs || [] @interval = opts[:interval].kind_of?(Fixnum) ? opts[:interval] : -1 @logger = opts[:logger] || Logger.new(STDOUT) @shutdown = false @running_syncs_thread = nil @sync_groups = [] Signal.trap('SIGINT', lambda{ raise Interrupt, 'SIGINT' }) Signal.trap('SIGQUIT', lambda{ raise Interrupt, 'SIGQUIT' }) Signal.trap('TERM', lambda{ raise Interrupt, 'TERM' }) end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
7 8 9 |
# File 'lib/inbox-sync/runner.rb', line 7 def interval @interval end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/inbox-sync/runner.rb', line 7 def logger @logger end |
#syncs ⇒ Object (readonly)
Returns the value of attribute syncs.
7 8 9 |
# File 'lib/inbox-sync/runner.rb', line 7 def syncs @syncs end |
Instance Method Details
#shutdown? ⇒ Boolean
43 44 45 |
# File 'lib/inbox-sync/runner.rb', line 43 def shutdown? !!@shutdown end |
#start ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/inbox-sync/runner.rb', line 27 def start startup! loop do loop_run break if shutdown? end shutdown! end |
#stop ⇒ Object
36 37 38 39 40 41 |
# File 'lib/inbox-sync/runner.rb', line 36 def stop if @shutdown != true main_log "Stop signal - waiting for any running syncs to finish." @shutdown = true end end |