I am using Sidekiq with Rails 3, with the following worker class:
class BotWorker
include Sidekiq::Worker
def perform(user_id)
user = User.find(user_id)
puts user.email
if condition # always true for now
BotWorker.perform_in(1.hour, user_id) # not working
end
end
end
My controller simply has
BotWorker.perform_async(user_id)
However, on the Sidekiq dashboard, it doesn't seem like another worker is scheduled.
Also would like to note that the recurrence is conditional so it doesn't seem like I can use sidetiq or some sidekiq scheduling extension.
Still new to Sidekiq, read the documentation. What am I missing?
Strange. I do the same thing except use self.class
instead of BotWorker
and it works. I don't have any arguments for my perform
method though.
You might want to wrap your method in a begin/rescue/ensure block and move the re-queuing into the ensure block.
If User.find
fails to find a user, it's going to raise an error which Sidekiq will catch and should move your job into the Retry queue. Probably not what you want.