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?

バッチ処理が設定した時間になっても動かない

Last updated at Posted at 2025-06-24

Laravelでバッチ処理を作成後、Kernelファイルで時間を設定しても指定した時間にバッチ処理が動かなかった。

対処法

config/app.phpファイルのtimezoneが日本時間になっているか確認する。

詳細

'timezone' => 'UTC',

config/app.phpファイルのタイムゾーンの箇所を見ると上記のように設定されていた。

UTCとは協定世界時と言い、世界で基準となる時間のことらしい。

このUTCに+9時間すると日本時間になる。

このままの設定だと、仮に日本時間で「毎日18時に実行」と設定していても、実際にはUTCの18時(日本時間の27時=翌朝3時)に動くことになる。

このtimezoneを

'timezone' => 'Asia/Tokyo',

というように書き換えた。

このように設定することで、Laravelが日本時間で日時を扱うようになり、スケジュールも日本時間で動くようになる。

その後

php artisan config:clear

を実行してキャッシュをクリアしたことで、設定した時間にバッチ処理を動かすことができるようになった。

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?