lib/kryten/runner.rb in kryten-0.2.1 vs lib/kryten/runner.rb in kryten-0.3.0
- old
+ new
@@ -2,16 +2,21 @@
attr_accessor :timer
attr_reader :running, :started
def initialize title=nil
@name, @running, @started = title, false, false
+ end
+
+ def setup
+ log "setting up"
Signal.trap("INT", proc { stop_running })
+ Signal.trap("TERM", proc { stop_running })
end
def start
setup
- log "starting"
+ log "started"
@started = true
while started do
sleep timer
@running = true
@@ -20,30 +25,24 @@
end
log "stopped"
true
rescue => e
- log "error #{e}"
- #raise
+ log :error, "error: #{e} - from: #{e.backtrace.first}"
+ raise
end
- def run
- log "running"
- end
-
def timer
@timer || 4
end
+ # stop the loop
def stop_running
@started = false
+ shutdown
end
- def setup
- log "setting up"
- end
-
def debug
log "debugging"
setup
2.times do
run
@@ -62,7 +61,12 @@
def status
log [started ? 'on and ' : 'off and ',
running ? 'running' : 'sleeping'].join
started
end
+
+ # hook methods
+ def shutdown; nil; end
+
+ def run; nil; end
end