帮助“每当” Ruby 中用于 cron 任务的 gem
我以前没有使用过 cron,所以我不能确定我这样做是否正确。我想要自动化的任务似乎没有运行。我在终端中执行了以下步骤:
- sudo gem install每当
- 更改到应用程序目录
- 每当。 (这创建了文件schedule.rb)
我将此代码添加到schedule.rb:
每 10 分钟一次 跑步者“User.vote”,环境=> “发展” 结尾 每小时做一次 跑步者“Digest.rss”,:环境=> “发展” 结尾
我将此代码添加到deploy.rb:
在“deploy:symlink”、“deploy:update_crontab”之后 命名空间:部署做 desc“更新 crontab 文件” 任务:update_crontab,:角色=> :db 做 运行“cd #{current_path} && 每当 --update-crontab #{application}” 结尾 结尾
我在终端中执行了此操作:每当
它返回:
@hourly cd /Users/RedApple/S && script/runner -e 开发 'Digest.rss' 0,10,20,30,40,50 * * * * cd /Users/RedApple/S && script/runner -edevelopment 'User.vote'
在终端中单独运行这些命令:
script/runner -edevelopment 'Digest.rss' script/runner -edevelopment 'User.vote'
现在在开发模式(脚本/服务器)下运行本地服务器,我没有看到任何证据表明代码实际上正在运行。是不是有什么步骤我没做?除了我所做的之外,没有“每当”的指南显示任何其他内容。
I have not used cron before, so I can't be sure that I did this right. The tasks I want to be automated don't seem to be running. I did these steps in the terminal:
- sudo gem install whenever
- change to the application directory
- wheneverize . (this created the file schedule.rb)
I added this code to schedule.rb:
every 10.minutes do runner "User.vote", environment => "development" end every :hour do runner "Digest.rss", :environment => "development" end
I added this code to deploy.rb:
after "deploy:symlink", "deploy:update_crontab" namespace :deploy do desc "Update the crontab file" task :update_crontab, :roles => :db do run "cd #{current_path} && whenever --update-crontab #{application}" end end
I did this in the terminal: whenever
It returned:
@hourly cd /Users/RedApple/S && script/runner -e development 'Digest.rss' 0,10,20,30,40,50 * * * * cd /Users/RedApple/S && script/runner -e development 'User.vote'
Running these commands individually in the terminal works:
script/runner -e development 'Digest.rss' script/runner -e development 'User.vote'
Now running a local server in development mode, script/server, I don't see any evidence that the code is actually being run. Is there some step that I didn't do? No guides for "Whenever" show anything else than what I have done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对任何时候都很陌生,但我认为运行只是
向您展示了创建的 cron 作业的样子。为了实际编写 cron 作业(使其处于活动状态),您需要执行:
这将为您提供完整的选项列表:
I'm new to whenever as well, but i think that just running
just shows you what the cron job that is created will look like. In order to actually write the cron job (to make it active), you need to execute:
This will get you a full list of options: