lib/hawking.rb in hawking-0.2 vs lib/hawking.rb in hawking-0.3

- old
+ new

@@ -3,27 +3,26 @@ require "timeout" module Hawking extend self - VERSION = "0.2" + VERSION = "0.3" def run - puts "Working #{@@jobs.size} jobs: [ #{@@jobs.keys.join(' ')} ]\r\r" + puts "Working #{@@jobs.size} jobs: [ #{@@jobs.keys.join(' ')} ]" server = TCPServer.open "127.0.0.1", 4481 loop { work_jobs server } end def work_jobs(server) Thread.start(server.accept) do |listener| + job = JSON.parse listener.gets, symbolize_names: true + puts "Working on #{job[:queue]} (#{job[:data]})" + begin Timeout::timeout(20) do - puts "Working on #{job[:queue]} (#{job[:data]})\r" - - job = JSON.parse listener.gets, symbolize_names: true - handler = @@jobs[job[:queue]] handler.call(job[:data]) end rescue Timeout::Error raise "The job hit 20 seconds timeout"