0

我写了一个 cronjob,但即使我更新了我的 schedule.rb,它也不会开始工作。我使用 javan/无论何时。我在用:

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

这是我的日程安排.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'
4

1 回答 1

1

看起来您的 production.rb 文件第 69 行存在问题。知道那是什么吗?

此外,为了启动使用时编写的 cronjob,您需要运行

whenever --update-crontab uniquejobname

其中 uniquejobname 是 cronjob 的一些标识符

于 2013-08-03T01:09:20.440 回答