在Rails中计划一次性作业 [英] Schedule one-time jobs in Rails

查看:123
本文介绍了在Rails中计划一次性作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在rails中调度作业,方法将在模型上调用。我知道有几个基于cron的宝石,但这些都是重复作业,在那里,我需要执行的工作只有一次,在一个设定的时间。是否有一个gem会这样做?

I need to schedule a job in rails, where a method will called on a model. I know there are several cron-based gems, but these are all for repeating jobs, where as I need to perform the job only once, at a set time. Is there a gem that will do this?

推荐答案

Rails 4.2将有用于调度作业的活动作业框架。您可以在Rails 4.1中使用 Active Job gem。它作为几个排队系统的标准化包装器,包括Sidekiq和Resque(都需要Redis来处理延迟的作业)。

Rails 4.2 will have the Active Job framework for scheduling jobs. You can use the Active Job gem in Rails 4.1. It serves as a standardized wrapper for several queueing systems, including Sidekiq and Resque (both require Redis to handle delayed jobs). Using Active Job gives you the flexibility of swapping out the queueing system if necessary.

您可以使用活动作业计划作业,如下所示:

You can schedule a job with Active Job like this:

MyJob.enqueue_at(5.hours.from_now, record)

Rails维护者希望这成为安排作业的标准机制。

The Rails maintainers intend for this to become the standard mechanism for scheduling jobs.

请查看 rails-mailinglist-signup 示例应用程序,以了解如何使用活动作业。

Have a look at the rails-mailinglist-signup example application to see how to use Active Job.

这篇关于在Rails中计划一次性作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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