Make delayed job run at specific date time

眉间皱痕 提交于 2019-12-11 04:41:49

问题


I want to send some emails through 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?


回答1:


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

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



来源:https://stackoverflow.com/questions/39713242/make-delayed-job-run-at-specific-date-time

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