14

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.

Farski
  • 1,670
  • 3
  • 15
  • 30

2 Answers2

7

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

Utgarda
  • 686
  • 4
  • 23
4

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) } }
ar31an
  • 241
  • 5
  • 9