1

谁能给我一个提示,如何为在 Amazon EC2 (Ubuntu) 上运行的 Rails 应用程序设置 CRON 作业?

试图找到一些教程或提示如何使其工作,但仍然没有任何成功。谢谢

4

3 回答 3

1

尝试创建一个模型方法来为您的 crondjob 执行任务。您可以使用 rails runner 来执行脚本。

rails runner 'User.deliver_reminder_emails!'

每当 gem 甚至可以做更高级的事情:https ://github.com/javan/whenever

于 2013-09-28T22:49:13.087 回答
0

You should have a look at rake tasks. Check this, this and this.

Running them is as simple as

rake foo:bar

You can schedule the same in your crontab; You might need to setup the correct PATH variable in case you are managing gems locally using rvm and bundler.

于 2013-09-29T03:21:28.190 回答
0

这对我来说相当棘手,因为 ELB-EC2 实例试图以 root 身份运行 cron 作业,这似乎导致了一组不同的权限、捆绑等。

这有点hacky,但这有效:

 sudo su ec2-user bin/bash -lc "cd /var/app/current && /opt/rubies/ruby-2.1.8/bin/bundle exec/bundle exec rails runner -e your_env \"Model.do_something\""

基本上,su 给通常运行 rails 的用户,并明确说明 bundle 的路径。

于 2017-11-07T02:29:32.393 回答