我写了一个cronjob,但即使我更新了我的schedule.rb也不会开始工作。我用过javan / when。我正在使用:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.3.0]
当我crontab -l:
# Begin Whenever generated tasks for: company_list
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
* * * * * /bin/bash -l -c 'cd /Users/-/rails_projects/company_list && script/rails runner -e production '\''Company.update_all_likes'\'' >> /Users/-/rails_projects/company_list/log/cron.log 2>&1'
# End Whenever generated tasks for: company_list
这是我的schedule.rb
set :output, "#{path}/log/cron.log"
env :PATH, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
every 1.minute do
runner "Company.update_all_likes"
end
公司型号:
def update_all_likes
$i = 0
while $i < Company.size do
uri = URI("http://graph.facebook.com/" + Company.find[$i].fbid)
data = Net::HTTP.get(uri)
update_attribute(:likes,JSON.parse(data)['likes'])
$i +=1
end
end
错误日志(更新2):
/Users/=/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.13/lib/rails/commands/runner.rb:53:in `eval': Could not find table 'companies' (ActiveRecord::StatementInvalid)
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `yield'
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `default'
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:228:in `columns'
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:248:in `column_names'
from /Users/=/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.13/lib/active_record/relation/calculations.rb:221:in `aggregate_column'
答案 0 :(得分:1)
看起来你的production.rb文件存在问题,第69行。你知道那是什么吗?
另外,为了启动随时使用的cronjob,你需要运行
whenever --update-crontab uniquejobname
其中uniquejobname是cronjob的一些标识符