9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Rails4] wheneverを使ってcrontabを管理して、cronを回す

Last updated at Posted at 2015-03-20

Rails4のプロジェクトを動かしているさくらvpsでcronを回すことになりまして、wheneverをつかってみたので、そのメモです。

Install

Gemfile
gem 'whenever', :require => false

Make config file

$ wheneverize .
---
[add] writing `./config/schedule.rb'
[done] wheneverized!

Write config

設定の方法

Github

酒と泪とRubyとRailsと

今回は使った設定

  • ログファイル
set :output, {:error => 'log/error.log', :standard => 'log/cron.log'}
  • シェル、コマンド設定
set :job_template, "/bin/zsh -l -c ':job'"
  • 環境
set :environment, :development
  • 日時指定
every '0 0 27-31 * * ' do
  rake "keihiseisan:please"
end
  • 曜日ごと
every :monday, :at => '10am' do # Use any day of the week or :weekend, :weekday
  command "echo '朝会やるよー'"
end
  • 5分ごと
every 5.minutes do
  runner "Welcome.test"
end

Register

save, update

$ whenever --update-cron

confirm

$ whenever

or

$ crontab -e

delete

$ whenever --clear-cron

Troubleshooting

command not found: bundleと出る場合

References

Github

酒と泪とRubyとRailsと

9
10
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
9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?