Rails 3 cron 通过应用程序?
我目前正在做
http://localhost:3000/MyApp/update
,它可以完成我想要的一切做。我尝试了elaided_job,但它不起作用,所以我尝试使用 cron 或其他一些方法来做同样的事情 - 我需要访问更新才能完成该任务,我希望它是在后台完成多次。
我也考虑过 cron + wget 但它看起来相当老套,并且 Mac 默认情况下没有附带 wget (这是最小的,但需要寻找替代方案)。
这样做的最佳方法是什么?
谢谢!
I'm currently doing
http://localhost:3000/MyApp/update
which does everything I want it to do. I tried delayed_job but it didn't work, so I'm trying to use cron or some other method to do the same thing - I need to access update in order for that task to be done, and I'd like it to be done in the background, multiple times.
I also considered cron + wget but it seems rather hacky, and Mac doesn't come with wget by default (which is minimal, but cause for looking at alternatives).
What's the best approach to do so?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
runner
在 Rails 环境上下文中执行任意 Ruby 代码,例如,假设您有一个如下文件:User.all.each { |u| u.send_email_update }
比您可以从命令行运行它,例如:
RAILS_ENV=生产rails runner /path/to/script.rb
将其放入 cron 中并执行它。
当然,请确保运行 cron 的用户的
$PATH
中有rails
或仅通过其绝对路径指定命令。You can execute arbitrary Ruby code in the context of a Rails environment by using
runner
, e.g. say you had a file like:User.all.each { |u| u.send_email_update }
than you could run it from the command line like:
RAILS_ENV=production rails runner /path/to/script.rb
Put that in a cron and smoke it.
Of course, ensure that the user running the cron has
rails
in their$PATH
or just specify the command via its absolute path.