lib/hawking.rb in hawking-0.1 vs lib/hawking.rb in hawking-0.2
- old
+ new
@@ -3,33 +3,33 @@
require "timeout"
module Hawking
extend self
- VERSION = "0.1"
+ VERSION = "0.2"
def run
- puts "Working #{@@jobs.size} jobs: [ #{@@jobs.keys.join(' ')} ]"
+ puts "Working #{@@jobs.size} jobs: [ #{@@jobs.keys.join(' ')} ]\r\r"
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
+ begin
+ Timeout::timeout(20) do
+ puts "Working on #{job[:queue]} (#{job[:data]})\r"
- puts "Working on #{job[:queue]} (#{job[:data]})"
+ job = JSON.parse listener.gets, symbolize_names: true
- begin
- Timeout::timeout(120) do
handler = @@jobs[job[:queue]]
handler.call(job[:data])
end
rescue Timeout::Error
- raise "The job hit 120 seconds timeout"
+ raise "The job hit 20 seconds timeout"
end
end
end
def job(queue, &block)
@@ -45,10 +45,10 @@
def initialize
@socket = TCPSocket.open "127.0.0.1", 4481
end
def put(queue, data)
- info = JSON.generate :queue => queue, :data => data
+ info = JSON.generate queue: queue, data: data
@socket.write info
@socket.close
end
end