I have a Laravel Scheduled job defined in Kernel.php
.
$schedule->call('\App\Http\Controllers\ScheduleController@processQueuedMessages')
->everyFiveMinutes()
->name('process_queued_messages')
->withoutOverlapping();
During development, my job threw an exception due to a syntax error. I corrected the mistake and tried executing it again, but it won't.
I tried artisan down
and then artisan up
. I also tried restarting the server instance. But nothing would help. The job just didn't get executed (there was no exception either).
I realize the problem is due to ->withoutOverlapping()
. Somehow, the Laravel scheduler thinks that the job is already running and does not execute it again.
Note: This solution is applicable for Laravel 5
Later versions of Laravel have updated the withoutOverlapping()
function. Refer to @nmargaritis's answer.
I found the solution by looking at the vendor code.
Illuminate\Console\Scheduling\CallbackEvent.php
It creates a file in local storage with the name schedule-*
.
public function withoutOverlapping()
{
if ( ! isset($this->description))
{
throw new LogicException(
"A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'."
);
}
return $this->skip(function()
{
return file_exists($this->mutexPath());
});
}
protected function mutexPath()
{
return storage_path().'/framework/schedule-'.md5($this->description);
}
Deleting the file schedule-*
at storage/framework
resolved the issue.