如何在 Rails 项目中运行日常任务/脚本? [英] How to run daily tasks/scripts in a Rails project?

查看:19
本文介绍了如何在 Rails 项目中运行日常任务/脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序开发计费系统,但我不确定如何设置每天运行的脚本,一个用于发送付款提醒(电子邮件),另一个用于降级未订阅的订阅已续订.

I'm working on the billing system for my app, but I'm not sure how to go about setting up scripts that run daily, one to send out payment reminders (email), and another to downgrade subscriptions that have not been renewed.

  • 有关如何执行此操作的任何提示?
  • 有什么我需要注意的问题吗?
  • 我可以使用任何宝石吗?

我已经完成了大部分的采购,所以我不会寻找像 paypal_recurring 或 stripe 这样的宝石 - 只需要处理付款提醒和已过期帐户的交易.

I've completed most of the purchasing side already, so am not looking for gems like paypal_recurring, or stripe - just need to handle the payment reminders and dealing of accounts that have expired.

推荐答案

我已经用了很多种方法来做到这一点,并且有很多方法可以做到.我认为当前的最佳做法是使用 Resque 将作业和 Rescue Scheduler 安排他们.

I've done this a number of ways and there are a bunch of ways to do it. I think the current best practice is to use Resque to queue the jobs and Rescue Scheduler to schedule them.

Resque 是一款可靠的作业调度"应用程序,可以为您处理各种任务.Resque Scheduler 可以提供完整的 cron 表达式(除了其他调度任务的方法)来管理作业.

Resque is a solid 'job scheduling' app that can handle all kinds of tasks for you. Resque Scheduler can be fed full cron expressions (in addition to other methods of scheduling tasks) to manage the jobs.

这种方法的一个优点是您可以获得 Resque Web 应用程序,该应用程序为您提供了一个网络应用程序供您使用用于监视作业(或为一次性作业运行启动它们).

One of the advantages of this approach is that you get the Resque Web app that gives you a web app to use for monitoring the jobs (or launching them for one-off job runs).

我在 Heroku 中使用了这种方法,它运行良好且可靠.

I've used this approach with Heroku and it works well and has been reliable.

这篇关于如何在 Rails 项目中运行日常任务/脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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