laravelcronlaravel-scheduler

Scheduler command is not working at midnight in Laravel


I have setup a command to run every Saturday at midnight but it is not working I write this but not running

$schedule->command('weeklyRewardPoints')->weeklyOn(6, '00:00')->timezone('Asia/Dubai');

then I try this but again not working

$schedule->command('weeklyRewardPoints')->weeklyOn(6, '0:0')->timezone('Asia/Dubai');

Even I tried to run at any specific minute at midnight like this but still not working

$schedule->command('weeklyRewardPoints')->weeklyOn(6, '00:30')->timezone('Asia/Dubai');

It is working successfully any other hour and minutes but not at midnight hour and minutes

this is my cron job

* * * * 6     php /home/path-to-my-project/artisan schedule:run >> /dev/null 2>&1

Solution

  • Taken from the Laravel docs

    So, when using Laravel's scheduler, we only need to add a single cron configuration entry to our server that runs the schedule:run command every minute.

    the scheduler need cronjob needs to run every minute

    * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
    

    your scheduler runs every 6 minutes.

    You can furthermore write

    $schedule->command('weeklyRewardPoints')->weeklyOn(6)->timezone('Asia/Dubai');
    

    and remove the time from weeklyOn as it is predefined with 0:0.