有效地重新安排 ActiveJob (resque/sidekiq) [英] Efficiently reschedule ActiveJob (resque/sidekiq)

查看:56
本文介绍了有效地重新安排 ActiveJob (resque/sidekiq)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Rails 4.2 应用程序,该应用程序使用由 resque/sidekiq 支持的 ActiveJob 进行电子邮件调度.当用户创建时事通讯活动时,会在特定日期创建并安排新工作.这一切都很好,但是当用户更改交货日期时会发生什么.

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.

在这种情况下,每个作业都可以检查它是否应该交付,因此无效的作业将被忽略,只执行最后一个.这可以工作,但如果用户进行 1k 次编辑,将 1k-1 个无效作业推入队列 - 不好.我认为现有的工作应该更新或替换为新的工作.据我所知,在 Redis 队列中搜索 job_id 的速度很慢.

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.

在 Rails 中重新安排 ActiveJobs 的正确方法是什么(使用 resque/sidekiq)?

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.

另一种方法是重新设计您发送广告系列的方式:将交付日期存储在数据库中,并让 cron 每分钟检查需要现在交付的广告系列,然后立即创建 Sidekiq 作业.

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.

这篇关于有效地重新安排 ActiveJob (resque/sidekiq)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆