LoginSignup
18
19

More than 5 years have passed since last update.

whenever で定期処理をcronに設定したメモ

Last updated at Posted at 2014-07-04

月次で数字を記録する処理をしたかったのでwheneverを使ってみた。

タスクの作成

something.rbをrailsプロジェクト内のlib/tasks/以下に作成
class Tasks::Something
def self.execute
print "some action!!\n"
end
end

下記コマンドで実行されるかテスト
rails runner Tasks::Something.execute

whenever

Gemfileに追加してbundle install
gem 'whenever', :require => false

下記コマンドでconfig以下にschedule.rbが作成される
bundle exec wheneverize .

schedule.rbに設定を記述(参考:http://morizyun.github.io/blog/whenever-gem-rails-ruby-capistrano/)
every '0 1 1 * *' do
runner "Tasks::Something.execute", :environment => :production
end

crontabに登録して完了
bundle exec whenever --update-crontab

削除するとき
bundle exec whenever --clear-crontab

18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19