Search code examples
phplaravelcronscheduler

Laravel Scheduler running every minute regardless of specified schedule


I have the Laravel schedule command triggered in the crontab as:

* * * * * php /home/forge/site/artisan schedule:run

This is set via Forge.

Then, in app/Console/Kernel.php I'm triggering my job to run hourly:

$schedule->job(new GetRecentArtists())->hourly();

But it's still running every minute.

My understanding was that the artisan command needs running every minute so that job schedules can then be checked to see if the job needs triggering as per its' specific schedule.

Update

I've tried restarting the queue as suggested in the comment by Sahidul, and have confirmed that none of the built-in schedules (hourly, daily, etc) prevent it from running every minute.

When I remove the schedule from the crontab and run it via php artisan schedule:run, I get 'No scheduled commands are ready to run' but the task runs anyway.


Solution

  • This was a red herring. I had my log message showing the job as running in the __construct method of the job, rather than in the handle method.

    The job is constructed when the scheduler runs, then added to the queue to be executed as per the schedule - so the construct method was being called immediately, but the job wasn't actually being handled until the scheduled time.