Efficiently reschedule ActiveJob (resque/sidekiq)

帅比萌擦擦* 提交于 2019-12-09 13:50:03

问题


I'm playing with Rails 4.2 app which uses ActiveJob backed by resque/sidekiq for email scheduling. When a user creates newsletter campaign a new job is created and scheduled on certain date. That's all great but what happens when the user changes the delivery date.

In this case every job could check if it should be delivered or not thus invalid jobs would be ignored and only the last one would be executed. This could work but if a user would make 1k edits that would push 1k-1 invalid jobs into queue - not good. I believe that the existing job should be updated or replaced with a new one. As far as I know searching through the Redis queue for the job_id is slow.

What would be the proper way for rescheduling ActiveJobs in Rails (with resque/sidekiq)?


回答1:


There is none, jobs are not meant to be rescheduled. You have answered your own question:

In this case every job could check if it should be delivered or not thus invalid jobs would be ignored and only the last one would be executed.

The alternative is to re-architect how you send campaigns: store the delivery date in the database and have cron check every minute for campaigns which need delivery now and create the Sidekiq job right then.



来源:https://stackoverflow.com/questions/28212817/efficiently-reschedule-activejob-resque-sidekiq

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