Task scheduling runs every minute instead of the time that I set

Published 2 months ago by giwrgos

Hello,

I'm working a task scheduler on homestead on my local environment. I've set the following cron job

05 00 * * * php  /home/vagrant/Projects/Laravel/Game/artisan schedule:run

which basically needs to run once a day every midnight at 00:05, but instead it runs every minute. Can anyone tell me what I'm doing wrong?

Thanks

Cronix
Cronix
2 months ago (169,090 XP)

homestead already has a cron job running every minute, which executes schedule:run (which is how it is supposed to be). You shouldn't have to enter anything in cron.

You just need to schedule a job through the scheduler using ->dailyAt('00:05'); if you want it to run at 5 after midnight.

https://laravel.com/docs/5.5/scheduling

giwrgos

@Cronix is there a way to disable it? I have a console kernel class that creates random hours for the scheduler as cron

                foreach ($times as $time) {
                    $time = Carbon::createFromTimestamp($time);
                    $cron = $time->minute. ' '. $time->hour . ' ' . $time->day .' ' . $time->month .' * ';
                    $schedule->command('client:submit-details')->cron($cron);
                }
Cronix
Cronix
2 months ago (169,090 XP)

I guess remove the default cron job that's running every minute. But then you'd lose the whole purpose of having cron jobs in code as opposed to crontab and would have to create and maintain each cronjob on each server manually. It's much better to have it in code so it's a part of your repo, and you only ever need one actual cron job to execute all jobs no matter when they were.

Cronix
Cronix
2 months ago (169,090 XP)

You could also check the current date/time to see if it matches your $time in your loop, and execute the scheduled command if it is. That would allow you to keep everything in code still and do what you are wanting.

giwrgos

@Cronix i know but for now i have to disable them. do you know how i can do it?

Please sign in or create an account to participate in this conversation.