Laravel scheduler does not respect the time set I have a helper containing the function removeOldMessages() and a job scheduled for 2 am everyday as below in the Kernel.php
$schedule->call(removeOldMessages())->cron('0 2 * * *')->name('removeoldmessages')->withoutOverlapping()->onOneServer();
The function removeOldMessages() writes to the log so I can see the results. The issue is that the job runs every time the cronjob triggers that is every half an hour (Im on shared hosting). That is the scheduler does not respect the timing. Am I doing something wrong here?
Here is what I set into the cronjob in Cpanel
cd xxxx/laravel && /usr/local/bin/php -d register_argc_argv=On artisan schedule:run >> /dev/null 2>&1
What doesRemoveOldMessages look like?
call is expecting it to be an invokable class or a closure
Try it like this instead
$schedule->call(function() {
removeOldMessages();
})
->cron('0 2 * * *')
->name('removeoldmessages')
->withoutOverlapping()
->onOneServer();
doesRemoveOldMessages() is a function that returns true if successful and false otherwise
I guess your solution worked, hooray!
I will mark your reply as the answer and come back to you if the issue persists.
Thanks a lot
Please sign in or create an account to participate in this conversation.