最近我遇到了以下不使用任何 Gem 运行 cron 作业的教程
http://www.ameravant.com/posts/recurring-tasks-in-ruby-on-rails-using-runner-and-cron-jobs
我在 /app/delete_old_posts.rb 中创建一个文件
class DeleteOldPosts < ActiveRecord::Base
# This script deletes all posts that are over 5 minutes old
post_ids = Post.find(:all, :conditions => ["created_at < ?", 5.minutes.ago])
if post_ids.size > 0
Post.destroy(post_ids)
puts "#{post_ids.size} posts have been deleted!"
end
然后通过给出 crontab -e 命令并在我写的 cronjob 控制台中创建 cron 作业
*/2 * * * * /usr/bin/env ruby /home/abc/xyz/urjit.rajgor/workspace/thewall/rails/runner/home/XYZ/ABC/urjit.rajgor/workspace/thewall/app/delete_old_posts.rb
cron 作业每两分钟运行一次,但它不起作用
请帮助我。
谢谢