meredevelopment
3 months ago
220
1
Laravel

Missunderstanding php artisan schedule:run use

Posted 3 months ago by meredevelopment

Hi, I'm playing about with Jobs and scheduling. I'm trying to understand the way the scheduler respects the timing options like everyMinute() or daily(). At the moment I can't get the delay/schedule to be respected at all.

Scenario 1:

If I have this in Kernel.php:

protected function schedule(Schedule $schedule)
{
    $schedule->job(new ProcessThing)->everyMinute();
}

...and I have a job called ProcessThing at app/Jobs/ProcessThing.php with this handle:

public function handle()
{
    logger('ProcessThing fired');
}

...when I start php artisan queue:work and run php artisan schedule:run, the response is: Running scheduled command: App\Jobs\ProcessThing

and [timestamp] local.DEBUG: ProcessThing fired gets written to the log file.

Problem 1: That looks ok... but if I try php artisan schedule:run 5 times in quick succession, the process runs 5 times immedialtey. I'd have expected it to queue into the Jobs table, and fire every minute?

Scenario 2:

If I now change the schedule to this:

    $schedule->job(new ProcessThing)->everyFiveMinutes();

(after restarting the worker and flushing config just to be safe) If I now run php artisan schedule:run, the response is: No scheduled commands are ready to run.

Problem 2: I'd expected the job to be added to the jobs table, with an 'available' timestamp 5 mins from now. If I wait 5 mins and try php artisan schedule:run again, the job never gets queued or runs, and nothing is ever logged.

I think I'm fundamentally missunderstanding this scheduling thing, but can't see where. Please help if you can.

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