1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Remove 'started' worker data

This commit is contained in:
Mike Perham 2014-02-01 20:48:44 -08:00
parent e42f5d15e2
commit 398ad5f3ea
5 changed files with 8 additions and 37 deletions

View file

@ -404,11 +404,11 @@ module Sidekiq
#
# workers = Sidekiq::Workers.new
# workers.size => 2
# workers.each do |name, work, started_at|
# workers.each do |name, work|
# # name is a unique identifier per worker
# # work is a Hash which looks like:
# # { 'queue' => name, 'run_at' => timestamp, 'payload' => msg }
# # started_at is a String rep of the time when the worker started working on the job
# # run_at is an epoch Integer.
# end
class Workers
@ -418,12 +418,9 @@ module Sidekiq
Sidekiq.redis do |conn|
workers = conn.smembers("workers")
workers.each do |w|
msg, time = conn.multi do
conn.get("worker:#{w}")
conn.get("worker:#{w}:started")
end
msg = conn.get("worker:#{w}")
next unless msg
block.call(w, Sidekiq.load_json(msg), time)
block.call(w, Sidekiq.load_json(msg))
end
end
end

View file

@ -95,7 +95,6 @@ module Sidekiq
redis do |conn|
conn.multi do
conn.sadd('workers', identity)
conn.setex("worker:#{identity}:started", EXPIRY, Time.now.to_s)
hash = {:queue => queue, :payload => msg, :run_at => Time.now.to_i }
conn.setex("worker:#{identity}", EXPIRY, Sidekiq.dump_json(hash))
end
@ -119,7 +118,6 @@ module Sidekiq
result = conn.multi do
conn.srem("workers", identity)
conn.del("worker:#{identity}")
conn.del("worker:#{identity}:started")
conn.incrby("stat:processed", 1)
conn.incrby(processed, 1)
end

View file

@ -1,21 +0,0 @@
# YAML marshalling of instances can fail in some circumstances,
# e.g. when the instance has a handle to a Proc. This monkeypatch limits
# the YAML serialization to just AR's internal @attributes hash.
# The paperclip gem litters AR instances with Procs, for instance.
#
# Courtesy of @ryanlecompte https://gist.github.com/007b88ae90372d1a3321
#
if defined?(::ActiveRecord)
class ActiveRecord::Base
yaml_as "tag:ruby.yaml.org,2002:ActiveRecord"
def self.yaml_new(klass, tag, val)
klass.unscoped.find(val['attributes'][klass.primary_key])
end
def to_yaml_properties
['@attributes']
end
end
end

View file

@ -352,15 +352,14 @@ class TestApi < Sidekiq::Test
c.multi do
c.sadd('workers', s)
c.set("worker:#{s}", data)
c.set("worker:#{s}:started", Time.now.to_s)
end
end
assert_equal 1, w.size
w.each do |x, y, z|
w.each do |x, y|
assert_equal s, x
assert_equal 'default', y['queue']
assert_equal Time.now.year, DateTime.parse(z).year
assert_equal Time.now.year, Time.at(y['run_at']).year
end
end

View file

@ -32,7 +32,6 @@ class TestWeb < Sidekiq::Test
Sidekiq.redis do |conn|
identity = 'foo:1234-123abc:default'
conn.sadd('workers', identity)
conn.setex("worker:#{identity}:started", 10, Time.now.to_s)
hash = {:queue => 'critical', :payload => { 'class' => WebWorker.name, 'args' => [1,'abc'] }, :run_at => Time.now.to_i }
conn.setex("worker:#{identity}", 10, Sidekiq.dump_json(hash))
end
@ -283,7 +282,6 @@ class TestWeb < Sidekiq::Test
Sidekiq.redis do |conn|
identity = 'foo:1234-123abc:default'
conn.sadd('workers', identity)
conn.setex("worker:#{identity}:started", 10, Time.now.to_s)
hash = {:queue => 'critical', :payload => { 'class' => "FailWorker", 'args' => ["<a>hello</a>"] }, :run_at => Time.now.to_i }
conn.setex("worker:#{identity}", 10, Sidekiq.dump_json(hash))
end
@ -441,8 +439,8 @@ class TestWeb < Sidekiq::Test
process_id = rand(1000)
msg = "{\"queue\":\"default\",\"payload\":{\"retry\":true,\"queue\":\"default\",\"timeout\":20,\"backtrace\":5,\"class\":\"HardWorker\",\"args\":[\"bob\",10,5],\"jid\":\"2b5ad2b016f5e063a1c62872\"},\"run_at\":1361208995}"
Sidekiq.redis do |conn|
conn.sadd("workers", "mercury.home:#{process_id}-70215157189060:started")
conn.set("worker:mercury.home:#{process_id}-70215157189060:started", msg)
conn.sadd("workers", "mercury.home:#{process_id}-70215157189060:default")
conn.set("worker:mercury.home:#{process_id}-70215157189060:default", msg)
end
end
end