Sidekiq 安排相同的工作人员在完成后排队 [英] Sidekiq schedule same worker to queue when done
问题描述
我在 Rails 3 中使用 Sidekiq,具有以下工作类:
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
我的控制器只有
BotWorker.perform_async(user_id)
但是,在 Sidekiq 仪表板上,似乎没有安排其他工作人员.
However, on the Sidekiq dashboard, it doesn't seem like another worker is scheduled.
还要注意,重复是有条件的,所以我似乎不能使用 sidetiq 或一些 sidekiq 调度扩展.
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.
还是 Sidekiq 的新手,请阅读文档.我错过了什么?
Still new to Sidekiq, read the documentation. What am I missing?
推荐答案
奇怪.我做同样的事情,除了使用 self.class
而不是 BotWorker
并且它有效.我的 perform
方法没有任何参数.
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.
您可能希望将您的方法包装在 begin/rescue/ensure 块中,并将重新排队移动到 ensure 块中.
You might want to wrap your method in a begin/rescue/ensure block and move the re-queuing into the ensure block.
如果 User.find
无法找到用户,则会引发一个错误,Sidekiq 将捕获该错误并将您的作业移入重试队列.可能不是你想要的.
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.
这篇关于Sidekiq 安排相同的工作人员在完成后排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!