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
- #debug ⇒ Object
- #initialize(title = nil) ⇒ Object
- #log(message) ⇒ Object
- #name ⇒ Object
- #run ⇒ Object
- #setup ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop_running ⇒ Object
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
#debug ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/kryten/runner.rb', line 45 def debug log "debugging" setup 2.times do run sleep timer end end |
#initialize(title = nil) ⇒ Object
5 6 7 8 |
# File 'lib/kryten/runner.rb', line 5 def initialize title=nil @name, @running, @started = title, false, false Signal.trap("INT", proc { stop_running }) end |
#log(message) ⇒ Object
54 55 56 |
# File 'lib/kryten/runner.rb', line 54 def log puts [name, ].join(': ') end |
#name ⇒ Object
58 59 60 |
# File 'lib/kryten/runner.rb', line 58 def name @name || self.class.to_s.gsub('::','-').downcase end |
#run ⇒ Object
29 30 31 |
# File 'lib/kryten/runner.rb', line 29 def run log "running" end |
#setup ⇒ Object
41 42 43 |
# File 'lib/kryten/runner.rb', line 41 def setup log "setting up" end |
#start ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kryten/runner.rb', line 10 def start setup log "starting" @started = true while started do sleep timer @running = true run @running = false end log "stopped" true rescue => e log "error #{e}" #raise end |
#status ⇒ Object
62 63 64 65 66 |
# File 'lib/kryten/runner.rb', line 62 def status log [started ? 'on and ' : 'off and ', running ? 'running' : 'sleeping'].join started end |
#stop_running ⇒ Object
37 38 39 |
# File 'lib/kryten/runner.rb', line 37 def stop_running @started = false end |