Module: Kryten::Runner
- Included in:
- Task
- Defined in:
- lib/kryten/runner.rb
Instance Attribute Summary collapse
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
-
#timer ⇒ Object
Returns the value of attribute timer.
Instance Method Summary collapse
- #after_run ⇒ Object
- #after_setup ⇒ Object
- #before_run ⇒ Object
-
#before_setup ⇒ Object
hook methods.
- #debug ⇒ Object
- #initialize(title = nil) ⇒ Object
- #log(message) ⇒ Object
- #name ⇒ Object
- #run ⇒ Object
- #setup ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
-
#stop_running ⇒ Object
stop the loop.
Instance Attribute Details
#running ⇒ Object (readonly)
Returns the value of attribute running.
3 4 5 |
# File 'lib/kryten/runner.rb', line 3 def running @running end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
3 4 5 |
# File 'lib/kryten/runner.rb', line 3 def started @started end |
#timer ⇒ Object
Returns the value of attribute timer.
2 3 4 |
# File 'lib/kryten/runner.rb', line 2 def timer @timer end |
Instance Method Details
#after_run ⇒ Object
77 |
# File 'lib/kryten/runner.rb', line 77 def after_run; nil; end |
#after_setup ⇒ Object
74 |
# File 'lib/kryten/runner.rb', line 74 def after_setup; nil; end |
#before_run ⇒ Object
75 |
# File 'lib/kryten/runner.rb', line 75 def before_run; nil; end |
#before_setup ⇒ Object
hook methods
73 |
# File 'lib/kryten/runner.rb', line 73 def before_setup; nil; end |
#debug ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/kryten/runner.rb', line 49 def debug log "debugging" setup 2.times do run sleep timer end end |
#initialize(title = nil) ⇒ Object
5 6 7 |
# File 'lib/kryten/runner.rb', line 5 def initialize title=nil @name, @running, @started = title, false, false end |
#log(message) ⇒ Object
58 59 60 |
# File 'lib/kryten/runner.rb', line 58 def log puts [name, ].join(': ') end |
#name ⇒ Object
62 63 64 |
# File 'lib/kryten/runner.rb', line 62 def name @name || self.class.to_s.gsub('::','-').downcase end |
#run ⇒ Object
76 |
# File 'lib/kryten/runner.rb', line 76 def run; nil; end |
#setup ⇒ Object
9 10 11 12 13 |
# File 'lib/kryten/runner.rb', line 9 def setup log "setting up" Signal.trap("INT", proc { stop_running }) Signal.trap("TERM", proc { stop_running }) end |
#shutdown ⇒ Object
78 |
# File 'lib/kryten/runner.rb', line 78 def shutdown; nil; end |
#start ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kryten/runner.rb', line 15 def start before_setup setup after_setup log "started" @started = true while started do sleep timer @running = true before_run run after_run @running = false end log "stopped" true rescue => e log :error, "error: #{e} - from: #{e.backtrace.first}" raise end |
#status ⇒ Object
66 67 68 69 70 |
# File 'lib/kryten/runner.rb', line 66 def status log [started ? 'on and ' : 'off and ', running ? 'running' : 'sleeping'].join started end |
#stop_running ⇒ Object
stop the loop
44 45 46 47 |
# File 'lib/kryten/runner.rb', line 44 def stop_running @started = false shutdown end |