Best way to find a job anywhere in Sidekiq
Solution 1
Seems like you want to know your job's status at some moment after spawning it, also you keep its id. There are a couple of plugins exactly for that, they have similar functionality and virtually the same name:
Sidekiq::Status - I was its original author, now it's supported by more apt Ruby developers
SidekiqStatus - an alternative
[edit] the above may be outdated by now, just check Sidekiq's wiki to find queue/status management that suits you best: https://github.com/mperham/sidekiq/wiki/Related-Projects
Solution 2
Or you could do something like this, if you don't want to store JID:
ss = Sidekiq::ScheduledSet.new
rs = Sidekiq::RetrySet.new
qs = Sidekiq::Queue.new('feeds')
feed.sync if [ss, rs, qs].all?{ |s| s.none?{ |j| (j.klass == 'SomeWorker') && (j.args[0] == feed.id) && (j.args[1] == true) } }
Related videos on Youtube
Farski
Updated on June 04, 2022Comments
-
Farski almost 2 years
Is there an easy way to search through all of sidekiq (queues, retries, schedules, etc) for a specific job?
Currently I'm doing this:
if !Sidekiq::Queue.new("feeds").find {|j| j.args[0] == feed.id && j.args[1] == true } if !Sidekiq::RetrySet.new.find {|j| j.queue == 'feeds' && j.args[0] == feed.id && j.args[1] == true } if !Sidekiq::ScheduledSet.new.find {|j| j.queue == 'feeds' && j.args[0] == feed.id && j.args[1] == true } feed.sync end end end
But given how large queues can get, there's a chance the job could move between sets during the iteration and get missed.