PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 18, 2022

[FIXED] Laravel non-overlapping scheduled job not executing

 March 18, 2022     laravel, laravel-5     No comments   

Issue

I have a Laravel Scheduled job which is defined in Kernel.php like so

$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 error and tried executing it again; but for some reason 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 that the problem is due to ->withoutOverlapping(). Somehow, Laravel scheduler is thinking that the job is already running and hence is not executing it again.


Solution

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.



Answered By - linuxartisan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing