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)?
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