Sidekiq schedule same worker to queue when done

痞子三分冷 提交于 2019-12-01 04:55:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20894740/sidekiq-schedule-same-worker-to-queue-when-done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!