module Delayed::Runnable
Public Instance Methods
start()
click to toggle source
# File lib/delayed/runnable.rb, line 3 def start trap('TERM') { quit! } trap('INT') { quit! } say "Starting #{self.class.name}" Delayed.lifecycle.run_callbacks(:execute, nil) do loop do run! break if stop? end end ensure on_exit! end
Private Instance Methods
interruptable_sleep(seconds)
click to toggle source
# File lib/delayed/runnable.rb, line 23 def interruptable_sleep(seconds) IO.select([pipe[0]], nil, nil, seconds) end
on_exit!()
click to toggle source
# File lib/delayed/runnable.rb, line 21 def on_exit!; end
pipe()
click to toggle source
# File lib/delayed/runnable.rb, line 42 def pipe @pipe ||= IO.pipe end
quit!()
click to toggle source
# File lib/delayed/runnable.rb, line 35 def quit! Thread.new { say 'Exiting...' }.tap do |t| stop t.join end end
stop()
click to toggle source
# File lib/delayed/runnable.rb, line 27 def stop pipe[1].close end
stop?()
click to toggle source
# File lib/delayed/runnable.rb, line 31 def stop? pipe[1].closed? end