Ankheur's avatar
Level 15

Laravel 9 Scheduler stopped calling the job task

Hi everyone !

I got a strange bug this week. I've scheduled a job to be performed everyday at 10am (sending a mail to a few people depending on a condition) with a Cron task calling schedule:run

All worked well but it stopped a few days ago and I don't really know why ! If I dispatch the job through a route it works but when I call the schedule:run at the right time nothing happens !

The only changes in the code was that I removed the fruitcake/laravel-cors to replace it with the native Laravel middleware but I've reversed this change and still nothing (and the scheduler works on my local machine even without the fruitcake/laravel-cors package).

My scheduler function looks like this :

$schedule->job(new MailingRappelJob)->dailyAt('10:00');

And my job function :

...a few conditions...
Mail::to($contact->email)->queue(new RappelMail($contact));

Is there something I'm missing? A laravel 9 update that changed something with the scheduler ? Any ideas where the problem could come from ?

Thanks a lot !

0 likes
2 replies
LaryAI's avatar
Level 58

There are a few things that could be causing the issue. Here are some steps to try:

  1. Check the server time: Make sure that the server time is correct and matches the timezone set in the Laravel application. You can check the server time by running the date command in the terminal.

  2. Check the cron job: Make sure that the cron job is running correctly. You can check the cron logs to see if there are any errors. You can also try running the php artisan schedule:run command manually to see if the job is executed.

  3. Check the queue: Make sure that the queue is running correctly. You can check the queue logs to see if there are any errors. You can also try running the php artisan queue:work command manually to see if the job is executed.

  4. Check the email configuration: Make sure that the email configuration is correct. You can try sending a test email to see if it works.

If none of these steps work, you can try adding some debug statements to the job function to see if it is being executed. For example, you can add a log statement at the beginning of the function:

public function handle()
{
    Log::info('MailingRappelJob started');
    // ...
}

This will log a message to the Laravel log file when the job is executed. You can then check the log file to see if the message is there.

Ankheur's avatar
Level 15

In case the problem happened to someone else : After many unsuccessful tries, I recently updated my code and cleaned the cache (optimize:clear) and it seemed to work again...

1 like

Please or to participate in this conversation.