13
7

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.

【Laravel】スケジューラはいつ動く?

Last updated at Posted at 2018-08-22

Laravel にはコマンドスケジューラという機能がある。

詳しくは [ここ] を読んでってことなのだが
crontab に以下の様に記述しておくと、app/Console/Kernel.php の schedule メソッドに記述することで
色々スケジュール実行できるようになるというもの。

* * * * * php /あなたのプロジェクトのパス/artisan schedule:run >> /dev/null 2>&1

crontab をいちいち設定しなおす必要がないし、設定は Git などで管理できるのでメリットは多い。

で、日毎に実行とか月毎に実行とか色々指定できるのだが、
じゃ実際いつ動く?って情報が見つからなかったのでまとめておく。
分 時 日 月 曜日は cron の記述に対応。

メソッド 説明 曜日 補足
->cron('* * * * * *'); CRON記法 * * * * *
->everyMinute(); 毎分 *
->everyFiveMinutes(); 5分毎 */5
->everyTenMinutes(); 10分毎 */10
->everyFifteenMinutes(); 15分毎 */15
->everyThirtyMinutes(); 30分毎 0,30
->hourly(); 毎時 0
->hourlyAt(17); 毎時17分 17 設定値が入る
->daily(); 毎日深夜0時 0 0
->dailyAt('13:00'); 毎日13:00 0 13 :がないと分は0
->twiceDaily(1, 13); 毎日1:00と13:00時 0 1,13 ,で連結
->weekly(); 毎週 0 0 0 日曜0時
->monthly(); 毎月 0 0 1 1日0時
->monthlyOn(4, '15:00'); 毎月4日の15:00 0 15 4
->quarterly(); 四半期毎 0 0 1 1-12/3
->yearly(); 毎年 0 0 1 1
->weekdays(); ウイークデーのみ 1-5
->sundays(); 日曜だけ 0
->mondays(); 月曜だけ 1
->tuesdays(); 火曜だけ 2
->wednesdays(); 水曜だけ 3
->thursdays(); 木曜だけ 4
->fridays(); 金曜だけ 5
->saturdays(); 土曜だけ 6

空欄の部分は他と複数設定可能。
最後まで設定されなかった空欄は * で設定される。
例えば ->fridays()->daily() で金曜0時の設定になる。
確認はしていないが、既存の設定を上書きする設定を実行したら後勝ちになるはず。
例えば ->yearly()->dailyAt('13:00') だと1月1日13:00に実行されるはず(笑)。

- 目次 -

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?