Skip to content

Issue with task scheduler grouping #56497

@Mlekar

Description

@Mlekar

Laravel Version

12.21.0

PHP Version

8.4.11

Database Driver & Version

No response

Description

There seems to be an issue with grouping tasks in the scheduler in a specific way - I believe it's the same issue as specified in pull 53427 in the last comment made by @decadence.

I believe the issues arises when grouping tasks (with subgroups) in a specific way such as e.g.:

Schedule::days([1, 2, 3, 4, 5, 6])->group(function () {
    Schedule::between('07:00', '21:00')->group(function () {
        Schedule::call(Task1::class)->everyMinute();
        Schedule::call(Task2::class)->everyMinute();
    });

    Schedule::call(Task3::class)->at('23:45');
});

If we group the tasks in this way, we'd expect Task1 and Task2 to run every minute between 07:00 and 21:00 from Monday to Saturday (which works correctly) and Task3 to run once at 23:45 from Mon - Sat (which isn't the case) - Task3 never runs in this case, which we think is because the scheduler gets confused somehow and wants to run Task3 between 07:00 and 21:00 at 23:45.

If we schedule Task3 to run at an hour between 07:00 and 21:00 it works as expected, such as in the example below:

Schedule::days([1, 2, 3, 4, 5, 6])->group(function () {
    Schedule::between('07:00', '21:00')->group(function () {
        Schedule::call(Task1::class)->everyMinute();
        Schedule::call(Task2::class)->everyMinute();
    });

    Schedule::call(Task3::class)->at('08:00');
});

So it seems the call to between in the subgroup somehow messes with anything defined in the main group. We've resolved it for now by defining the schedule like:

Schedule::days([1, 2, 3, 4, 5, 6])->between('07:00', '21:00')->group(function () {
        Schedule::call(Task1::class)->everyMinute();
        Schedule::call(Task2::class)->everyMinute();
});

Schedule::days([1, 2, 3, 4, 5, 6])->group(function () {
        Schedule::call(Task3::class)->at('23:45');
});

Not sure if this is an actual bug or not, but I feel like approach nr. 1 should work, since nested grouping is supposedly supported and works in most cases except cases where you define different times with between and at and such.

Steps To Reproduce

Define some scheduler tasks in groups in a similar way as described above. The task that should run outside of the between window once per day will not run unless its time is within the between window.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions