cronjob を書きましたが、schedule.rb を更新しても動作しません。javan/whenever を使用しました。私は使っている:
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'