とよぶ

歌いながらコード書いてます

Wheneverでcrontabを管理する

railsでバッチ処理を作るにあたって、
crontabはwheneverというライブラリで管理する。

$ vim Gemfile
$ tail -2 Gemfile
gem 'whenever', :require => false
$ bundle install
$ wheneverize .
-bash: wheneverize: command not found
$ bundle wheneverize exec .
Could not find task "wheneverize".
$ bundle show whenever
/Users/takasing/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/whenever-0.8.4
$ /Users/takasing/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/whenever-0.8.4/bin/wheneverize .
[add] writing './config/schedule.rb'
[done] wheneverized!
$ ls -l config | grep schedule
-rw-r--r--  1 takasing  staff   483 Oct 11 22:09 schedule.rb
$ cat config/schedule.rb
set :output, "log/cron.log"
set :environment, :development

every 3.minute do
  runner "Tasks::Scraping.execute"
end

$ bundle exec whenever
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /Users/takasing/exercise/rails-practice && bin/rails runner -e development '\''Tasks::Scraping.execute'\'' >> /Users/takasing/exercise/rails-practice/log/cron.log 2>&1'

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
$ bundle exec whenever --update-crontab

広告を非表示にする