延迟作业与 cron

发布于 2024-12-08 20:11:57 字数 316 浏览 1 评论 0原文

我有一个系统,用户进来完成一个包含多个部分的申请流程 - 有时用户会保存他们的进度并稍后再回来。

如果用户在 48 小时内没有回来,我想向他们发送一封电子邮件 - 最好使用 crondelayed_job来执行此操作每当

我注意到,每当我在控制台中运行操作(例如 bundle installrake db:migrate)时,它也会运行 cron,这让我怀疑我们可能存在用户在同一天收到多个提醒的情况。

您对此有何建议?

I have a system where users come in to go through an application process that has multiple parts - sometimes users will save their progress and come back later.

I want to send users an e-mail if they haven't come back in 48 hours - would it be best to do this using cron, delayed_job, or whenever?

I've noticed that whenever I run operations in the console (such as bundle install or rake db:migrate) it runs cron as well, which makes me suspicious that we may have instances where users get multiple reminders in the same day.

What are your recommendations for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2024-12-15 20:11:57

首先,Whenever 和 Cron 是同义词。 Whenever 所做的一切就是为您提供一种使用 Ruby 编写 cronjobs 的方法(这太棒了,我喜欢 Everever)。

Delayed_job 不是这里的答案。你肯定想使用 cronjobs。在您的应用程序模型上创建一个方法,该方法将获取 updated_at 值为 的应用程序。 2.days.ago 并向申请人发送电子邮件。

def notify_stale_applicants
  @stale_applications = Application.where('updated_at < ?', 2.days.ago) # or 48.hours.ago
  @stale_applications.each do |app|
    UserMailer.notify_is_stale(app).deliver
  end
end

还有你的 UserMailer:

def notify_is_stale(application)
  @application = application
  mail(:to => application.user.email, :from => "Application Status <[email protected]>", :subject => "You haven't finished your Application!"
end

使用每当创建这个 cron:

every :day, :at => '8am' do
  runner 'Application.notify_stale_applicants'
end

First of all, Whenever and Cron are synonymous. All Whenever does is provide a way for you to write cronjobs using Ruby (which is awesome, I love Whenever).

Delayed_job is not the answer here. You definitely want to use cronjobs. Create a method on your Application model that will get applications which have an updated_at value of < 2.days.ago and e-mail its applicant.

def notify_stale_applicants
  @stale_applications = Application.where('updated_at < ?', 2.days.ago) # or 48.hours.ago
  @stale_applications.each do |app|
    UserMailer.notify_is_stale(app).deliver
  end
end

And your UserMailer:

def notify_is_stale(application)
  @application = application
  mail(:to => application.user.email, :from => "Application Status <[email protected]>", :subject => "You haven't finished your Application!"
end

Using whenever to create this cron:

every :day, :at => '8am' do
  runner 'Application.notify_stale_applicants'
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文