LoginSignup
10
11

More than 5 years have passed since last update.

Laravelのスケジューラでの排他制御(withoutOverlapping)について

Last updated at Posted at 2018-04-10

問題

ある日、アクセス集中によりサーバーがダウンする事態に見舞われた。
その後、サーバーを再起動してもバッチ処理が正しく実行されない問題が発生した。
バッチ処理はLaravelのスケジューラにより定期実行している。

原因

吐かれていたログは、

No scheduled commands are ready to run.

そういえばスケジューラで
多重起動の防止の設定をしていた。(withoutOverlapping()の指定。)

// 例
$schedule->command('emails:send')->withoutOverlapping();

どうやら、処理が正常に終了しなかったため、ロックファイルが残り続けており、その後の処理がスキップされてしまっていたようだった :cry:

対策

/storage/framework配下にロック用のファイル(schedule-XXXXXXXX)が生成されていたので、削除した。まぁ、それだけ。

その後、バッチは元気に仕事を再開してくれました :thumbsup_tone2:

補足:ロック用のファイルのファイル名

    /**
     * Get the mutex name for the scheduled command.
     *
     * @return string
     */
    public function mutexName()
    {
        return 'framework/schedule-'.sha1($this->description);
    }
10
11
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
10
11