使延迟的作业在特定日期时间运行 [英] Make delayed job run at specific date time

查看:80
本文介绍了使延迟的作业在特定日期时间运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 delayed_job

发送一些电子邮件,但是我想在事件。

However, I want to send them before and after an event.

我担心的是这是否真的有效:

My concern is if this will actually work:

def one_week_before_run
  AtendeeMailer.delay(run_at: '8th October 2016'.to_datetime).mudrun_about_to_start(self)
end

def thank_you_note
  AtendeeMailer.delay(run_at: '18th October 2016'.to_datetime.end_of_day).thank_you(self)
end

或我应该选择另一种方法吗?

or should I choose another approach?

推荐答案

仅当run_at< =当前时间时,延迟的作业才会选择要执行的作业。引用DJ的查询来选择工作

Delayed job picks a job to execute only if the run_at <= current time. Refer DJ's query to pick job

SELECT `delayed_jobs`.* FROM `delayed_jobs` WHERE ((run_at <= '2016-09-27 00:49:59' AND (locked_at IS NULL OR locked_at < '2016-09-27 00:24:59') OR locked_by = 'host:Madhubalans-Air pid:74314') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

您的代码将run_at设置为2016-10-18 00 :00:00和2016-10-18 23:59:59。
因此,您的代码将按您的期望运行:)

Your code is setting run_at to 2016-10-18 00:00:00 and 2016-10-18 23:59:59. So your code will work as per your expectation :)

这篇关于使延迟的作业在特定日期时间运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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