需要在特定时间运行作业

发布于 2024-11-08 22:34:44 字数 266 浏览 1 评论 0原文

我正在尝试创建一个作业以便向 Twilio 调用发送通知,因此拥有一个强大的解决方案可以确保作业在特定时间运行(我不认为被放入队列中)非常重要足够准确)。

此类任务的最佳解决方案是什么?

这些通知需要在通话中的特定时间发生。如“还剩1分钟”。因此,它需要能够:

  1. 在任意时间运行(下午 1:22 或凌晨 2:45)
  2. 由用户输入定义(他们设置调用时间)

(如果该解决方案可以在 Heroku 上运行,那就太好了)

I'm trying to create a job in order to send a notification to a Twilio call, therefore it is important to have a robust solution that can make sure jobs are run at a specific time (I don't think being put into a queue is accurate enough).

What is the best solution for this type of a task?

These notifications need to happen at a specific time in the call. Such as "1 minute left". Therefore it needs to be able to:

  1. Run at arbitrary times (1:22PM or 2:45AM)
  2. Be defined by user input (they set the time of the call)

(It would be nice if that solution could run on Heroku)

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

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

发布评论

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

评论(4

最终幸福 2024-11-15 22:34:44

您可以使用 Heroku cron 每天或每小时运行作业。

每日 cron 是免费的,每小时 cron 费用为 3 美元/月:http://addons.heroku.com/cron

通常,cron 在您首次启动时运行(即,如果您将其设置为下午 3 点,它将在每天下午 3 点运行),但您可以通过向 [电子邮件受保护]

要在 cron 中运行代码,请将代码添加到 cron.rake 文件并查看 cron 文档 此处

仅供参考

Heroku 自己的 cron 示例建议进行时间检查,即

if Time.now.hour % 4 == 0 # run every four hours
  ...

但是,如果您每天运行 cron,则代码将在可能失败上述条件的时间运行。因此,除非您支付每小时 cron 的费用并且您只希望它运行特定小时,否则请忽略他们的示例代码的这一部分,而通常只包含您自己的代码。

在特定时间运行

尝试 delayed_job:run_at 列,这可能为您提供在特定时间运行作业所需的灵活性。

Heroku 文档:http://devcenter.heroku.com/articles/delayed-job

You can use Heroku cron to run jobs either daily or hourly.

Daily cron is free, hourly cron costs $3/month: http://addons.heroku.com/cron.

Typically cron runs when you first initiate it (i.e. if you set it up at 3pm, it'll run at 3pm every day), but you can change that by sending an e-mail to [email protected].

To run code in a cron, add your code to a cron.rake file and check out the cron docs here.

FYI

Heroku's own samples for cron suggest doing a time check, i.e.

if Time.now.hour % 4 == 0 # run every four hours
  ...

But, if you are running a daily cron, the code will run at a time that is likely to fail the above conditional. So, unless you are paying for hourly cron and you only want it to run specific hours, leave out that part of their sample code and just include your own code normally.

Running at Specific Times

Try delayed_job's :run_at column, which may give you the flexibility you need to run jobs at very specific times.

Heroku Docs: http://devcenter.heroku.com/articles/delayed-job

゛时过境迁 2024-11-15 22:34:44

您需要为此添加一个 cronjob。如果您使用的是 Linux 机器,那么您可以将 cron 添加到 crontab 并指定它运行的时间。它非常灵活。您可以在这里找到详细信息:
http://en.wikipedia.org/wiki/Cron

如果你想在ruby 方式,每当 gem 时尝试:
https://github.com/javan/whenever

You need to add a cronjob for that. If you are on a Linux box then you can add a cron to the crontab and specify the time at which it runs. It is very flexible. You can find the details here:
http://en.wikipedia.org/wiki/Cron

If you want to do it in a ruby way, try whenever gem:
https://github.com/javan/whenever

你的心境我的脸 2024-11-15 22:34:44

对于您提到的具体情况,我认为您应该尝试delayed_job:
https://github.com/collectiveidea/delayed_job#readme

它有一个 run_at 选项,您可以在其中指定您要运行作业的时间。

For the specific case that you have mentioned, I think that you should give delayed_job a try:
https://github.com/collectiveidea/delayed_job#readme

it has a run_at option where you can specify the time at which you want to run the job.

瑾兮 2024-11-15 22:34:44

转到托管控制面板中的 cron 作业

Goto cron jobs in your hosting control panel

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