0
0

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.

Whenever 複数環境で動作させるスケジュールを共存させる

Last updated at Posted at 2019-02-14

@koshi_life です。

Whenever 便利で驚きました。
最近関わった案件で schedule.rb 内で複数環境でタスクを共存させたいシーンがあり、
情報がなかったので試した内容を備忘します。

(ちなみに、既存バッチが production で動作中の環境でログファイルと各種設定を分けたバッチを1本追加したいシーンでした。)

前提

  • Whenever v0.10.0
  • OS: macOS HighSierra

schedule.rb

set :environment, :HOGEHOGE を各タスクのスケジュール設定の手前で宣言するだけでした。

以下スケジュールを設定する例を示します。同じタスク Tasks::Hoge.execute を稼働させます。

  • 1つ目のスケジュール 毎時0分に production 環境
  • 2つ目のスケジュール 毎時30分に tmp 環境
config/schedule.rb

set :environment, :production
every :hour, at: 0 do
    runner "Tasks::Hoge.execute"
end

set :environment, :tmp
every :hour, at: 30 do
    runner "Tasks::Hoge.execute"
end

crontab 登録

$ bundle exec whenever --update-crontab
[write] crontab file updated

crontab 確認

$ crontab -l
# Begin Whenever generated tasks for: <RAILS_APP_PATH>/config/schedule.rb at: 2019-02-14 20:42:00 +0900
0 * * * * /bin/bash -l -c 'cd <RAILS_APP_PATH> && bundle exec bin/rails runner -e production '\''Tasks::Hoge.execute'\'''

30 * * * * /bin/bash -l -c 'cd <RAILS_APP_PATH> && bundle exec bin/rails runner -e tmp '\''Tasks::Hoge.execute'\'''

# End Whenever generated tasks for: <RAILS_APP_PATH>/config/schedule.rb at: 2019-02-14 20:42:00 +0900

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?