examples/evented.rb in raemon-0.1.2 vs examples/evented.rb in raemon-0.2.0
- old
+ new
@@ -13,35 +13,36 @@
def stop
logger.info "=> Stopping worker #{Process.pid}"
EM.stop_event_loop if EM.reactor_running?
- exit
end
- def execute
- EventMachine.run do
+ def run
+ EM.run do
@queue = EMJack::Connection.new
@queue.each_job(5) do |job|
logger.info "(#{Process.ppid}:#{Process.pid}) got job: #{job.inspect}"
# process(job)
@queue.delete(job)
- stop if shutting_down?
+ heartbeat!
end
@queue.on_error do |error|
case error
when :timed_out
- # We use the reserve timeout to check if we should shutdown
- stop if shutting_down?
+ # We use the reserve timeout for the heartbeat
+ heartbeat!
+
+ # Note: this will only run once.. we need to call the @queue.each_job
+ # again .. maybe put it in a block
else
logger.error error.to_s
end
end
end
end
-
end
-Raemon::Master.startup 2, EventedJobWorker
+Raemon::Master.start 2, EventedJobWorker