rails的cron作业:最佳实践? [英] A cron job for rails: best practices?

查看:193
本文介绍了rails的cron作业:最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails环境中运行计划任务的最佳方法是什么?脚本/ runner? Rake?

What's the best way to run scheduled tasks in a Rails environment? Script/runner? Rake?

推荐答案

我使用rake方法(由 heroku

I'm using the rake approach (as supported by heroku)

有一个名为lib / tasks / cron.rake的文件..



With a file called lib/tasks/cron.rake ..

task :cron => :environment do
  puts "Pulling new requests..."
  EdiListener.process_new_messages
  puts "done."
end

要从命令行执行,它只是rake cron。

To execute from the command line, this is just "rake cron". This command can then be put on the operating system cron/task scheduler as desired.

更新这是一个相当古老的问题和答案!一些新信息:

Update this is quite an old question and answer! Some new info:


  • 我引用的heroku cron服务已被替换为 Heroku Scheduler

  • 用于频繁的任务(尤其是你想避免Rails环境启动成本)是使用系统cron来调用一个脚本,它将(a)戳一个安全/私有的webhook API在后台调用所需的任务,或者(b)直接将一个任务放入你的队列系统上

这篇关于rails的cron作业:最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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