laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.62k stars 11.03k forks source link

Schedule group `when()` issue #53600

Closed rcerljenko closed 1 day ago

rcerljenko commented 1 day ago

Laravel Version

11.33.2

PHP Version

8.3

Database Driver & Version

No response

Description

First of all, I'm not sure if this is a issue with a when() function or a group() function but it happens after schedule group() comes after a when().

Consider this piece of code:

Schedule::daily()
    ->group(static function (ConsoleSchedule $schedule): void {
        $schedule->when(static fn (): bool => true)
            ->group(static function (ConsoleSchedule $schedule): void {
                // Schedule definitions under "when" condition
            });

        // Other daily schedule definitions
    });

All schedules should have the same cron expression (0 0 * * *) but, as it turns out, the inner group under when condition has a cron expression which triggers on every minute (* * * * *) and the outer group has the right one.

Something happens with the when -> group combo with cron definitions.

Steps To Reproduce

<?php

// routes/console.php

use Illuminate\Support\Facades\Schedule;
use Illuminate\Console\Scheduling\Schedule as ConsoleSchedule;

Schedule::onOneServer()
    ->runInBackground()
    ->withoutOverlapping()
    ->group(static function (ConsoleSchedule $schedule): void {
        // DAILY
        $schedule->daily()
            ->group(static function (ConsoleSchedule $schedule): void {
                $schedule->when(static fn (): bool => true)
                    ->group(static function (ConsoleSchedule $schedule): void {
                        // Schedule definitions under "when" condition
                    });

                // Other daily schedule definitions
            });
    });