Framework: Scheduled task doesn't run

Created on 17 Apr 2018  ·  12Comments  ·  Source: laravel/framework

  • Laravel Version: 5.6.16

    • PHP Version: PHP 7.2.1-1

    • Database Driver & Version: mariadb Ver 15.1 Distrib 10.1.26-MariaDB

      Description:


Hi
I have followed the steps on the documentation to run scheduled task, i have set up the cron entry to
* * * * * php /path-to-your-project/artisan schedule:run >> /home/artisan_cron.log 2>&1

Then setup my job task in Kernel.php $schedule->job(new FichierMouvementJob())->when(true); but nothing is running.
The output in the /home/artisan_cron.log is always "No scheduled commands are ready to run."

I've made some search in the source code and the problem seems to be that the Schedule instance in the constructor of ScheduleRunCommand.php isn't a singleton. It seems that it is a fresh injected instance, thus losing all the events (task).
Replacing $this->schedule->dueEvents($this->laravel) by app(Schedule::class)->dueEvents($this->laravel) in ScheduleRunCommand::handle() solves the problem and the task is running correctly.
Anyone is having the same issue ?

----EDIT 30/04/2018 ----
This bug seems to appear only when
APP_ENV=local and APP_DEBUG=true

Steps To Reproduce:

Set a task in Kernel.php, see if it is running correctly.

Most helpful comment

Hello,

we were calling Artisan::call() inside boot method of one of our provider and it caused the issue.
When doing that, it instantiate commands sooner than intended, before the execution of the schedule method in the console kernel. And since the ScheduleRunCommand has the Scheduler in it's constructor, and it's not up to date with the one edited by the console kernel, jobs are not running.

All 12 comments

Not really. Working on an app with lots of jobs and not seeing any problem.

What QUEUE_DRIVER are you using in your ENV?
database?, sync?

QUEUE_DRIVER=database

Did you run the ‘queue:table’ command to generate the table where all your jobs will be stored?

If you don’t have the table, then it makes sense that no jobs are never found.

I have a lot of jobs running fine already. My queue driver is working fine.

Great, please consider closing the issue! 😊

The issue is on the scheduler not the queue. The scheduler doesn't work event with $schedule->call().
It has nothing to deal with the queue

Since 5.6.22 the problem seems to be solved

@meyer59 Did you find the root cause of the issue and better solution for it? I am facing the same issue in my application with Laravel 5.5.40.
Replacing $this->schedule->dueEvents($this->laravel) by app(Schedule::class)->dueEvents($this->laravel) in ScheduleRunCommand::handle() does solve the issue but I am still not sure what caused the issue in the first place as it was working fine last time I updated the application and we have not updated framework since the last update on the server.

No really. I upgraded the framework to the next release at that time and worked.

Le 3 sept. 2018 à 08:02, Manish Verma notifications@github.com a écrit :

@meyer59 Did you find the root cause of the issue and better solution for it? I am facing the same issue while in my application with Laravel 5.5.40


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Hello,

we were calling Artisan::call() inside boot method of one of our provider and it caused the issue.
When doing that, it instantiate commands sooner than intended, before the execution of the schedule method in the console kernel. And since the ScheduleRunCommand has the Scheduler in it's constructor, and it's not up to date with the one edited by the console kernel, jobs are not running.

@ik

Hello,

we were calling Artisan::call() inside boot method of one of our provider and it caused the issue.
When doing that, it instantiate commands sooner than intended, before the execution of the schedule method in the console kernel. And since the ScheduleRunCommand has the Scheduler in it's constructor, and it's not up to date with the one edited by the console kernel, jobs are not running.

@lk77 You just made my day 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  ·  3Comments

gabriellimo picture gabriellimo  ·  3Comments

ghost picture ghost  ·  3Comments

shopblocks picture shopblocks  ·  3Comments

klimentLambevski picture klimentLambevski  ·  3Comments