简体   繁体   English

rails + sidekiq特定的日期和时间作业

[英]rails + sidekiq specific date and time job

我们如何使用db time使用rails将作业添加到sidekiq中的特定日期和时间,我想在约会时间到来时发送电子邮件,那么什么是最好的方法呢?

You might refer to the native Active Job API introduce in rails 4.2 (which come in front of Sidekiq). 您可能会参考rails 4.2(在Sidekiq前面)引入的本机Active Job API。

You build job with the rails API, you specify in conf file that you use sidekiq, and rails will put the job in sidekiq. 使用rails API构建作业,在conf文件中指定使用sidekiq,然后rails会将作业放入sidekiq。

Advantages : You can switch to another enqueuing gem, easier to delay job at a specific date, you can perform after_action, which are normally in the professional version of Sidekiq. 优点:您可以切换到另一个入队的gem,更容易在特定日期延迟工作,可以执行after_action,通常在Sidekiq的专业版本中。

See the tutorial to learn more about it : http://edgeguides.rubyonrails.org/active_job_basics.html 请参阅该教程以了解更多信息: http : //edgeguides.rubyonrails.org/active_job_basics.html

A quick example : 一个简单的例子:

# Enqueue a job to be performed tomorrow at noon. MyJob.set(wait_until: Date.tomorrow.noon).perform_later(record)

Hope it help 希望对你有帮助

Attach an appointment date (or even better a specific appointment notification datetime) to the appointment model. 将约会日期(甚至最好是特定的约会通知日期时间)附加到约会模型。

Then have a background job queued every minute that checks for all the unsent notifications for close events (for instance events where the appointment notification is lower than 1 minute in the future and not sent yet) and for each appointment queue an email to be sent. 然后让后台作业每分钟排队,检查所有未发送的关闭事件通知(例如,约会通知低于1分钟且尚未发送的事件),并为每个约会队列发送一封电子邮件。

You may want to use sidekiq to queue the emails, and a cron system such as clockwork to enqueue a task on sidekiq to check every minute for notifications to be sent. 您可能要使用sidekiq将电子邮件排队,并使用cron系统(例如clockwork将任务排入sidekiq以检查每分钟是否有要发送的通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM