lib/pigato/worker.rb in pigato-0.4.3 vs lib/pigato/worker.rb in pigato-0.4.4

- old
+ new

@@ -9,18 +9,17 @@ @service = service @conf = { :autostart => false, :timeout => 2500, - :heartbeat => 2500, :reconnect => 2500 } @conf.merge!(conf) + @heartbeat_at = Time.now @liveness = 0 - @heartbeat_at = 0 @reply_to = nil @reply_rid = nil @reply_service = nil init @@ -39,17 +38,17 @@ request = [Pigato::C_CLIENT, Pigato::W_HEARTBEAT, "worker", sid] msg = ZMQ::Message.new request.reverse.each{|p| msg.push(ZMQ::Frame(p))} client.send msg end - @@global_heartbeat_at = Time.now + 2 + @@global_heartbeat_at = Time.now + 1 end rescue => e puts e end @@mtx.unlock - sleep 2 + sleep 1 end end end def reply reply @@ -103,25 +102,24 @@ if @liveness == 0 sleep 0.001 * @conf[:reconnect] start end end - + if Time.now > @heartbeat_at - send Pigato::W_HEARTBEAT - @heartbeat_at = Time.now + 0.001 * @conf[:heartbeat] + send(Pigato::W_HEARTBEAT, ['', Oj.dump({ 'concurrency' => 1 })]) + @heartbeat_at = Time.now + 0.001 * @conf[:timeout] end - + val end def start stop sock_create send Pigato::W_READY, @service super @liveness = HEARTBEAT_LIVENESS - @heartbeat_at = Time.now + 0.001 * @conf[:heartbeat] end def stop sock_close super