whenever でcron設定
環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqlite/MySQL(予定))
classとして作成した機能を毎日定時に実行するため、wheneverを導入してcrontab を設定。
(参考URL)
なんちゃってGeek(仮): Rails4.0でcron(バッチ処理)を動かす設定
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
実行するファイル
# vim lib/tasks/search_task.rb
config/application.rbファイルに以下を追加。
config.autoload_paths += %W(#{config.root}/lib)
実行テスト
rails runner Tasks::SearchTask.execute
# vim Gemfile
gem 'whenever', :require => false
# bundle install
# wheneverize .
# vim config/schedule.rb
set :output, 'log/cron.log'
set :environment, :production
every 1.day, :at => '8:00 am' do
runner 'Tasks::SearchTask.execute'
end
# bundle exec whenever
# bundle exec whenever --update-crontab
# crontab -l
⇒設定を/etc/crontabに移動