Skip to content

AsPeriodicTask results in JitterTrigger::getNextRunDate() returns null #61872

@sveldhuisen

Description

@sveldhuisen

Symfony version(s) affected

7.3.2

Description

I'm using AsPeriodicTask on my Command to schedule it according to the following attribute definition:

#[AsPeriodicTask(frequency: '30 minutes', from: '06:00 Europe/Amsterdam', until: '23:50 Europe/Amsterdam', jitter: 120, arguments: null, schedule: 'default')]

I end up with a bunch of PHP critical messages in my prd.log starting at 23:00::47 and ending at 23:59:59:

[2025-09-28T23:59:59.356282+02:00] php.CRITICAL: Uncaught Error: Symfony\Component\Scheduler\Trigger\JitterTrigger::getNextRunDate(): Argument #1 ($run) must be of type DateTimeImmutable, null given, called in /application/vendor/symfony/scheduler/Generator/MessageGenerator.php on line 81 {"exception":"[object] (TypeError(code: 0): Symfony\\Component\\Scheduler\\Trigger\\JitterTrigger::getNextRunDate(): Argument #1 ($run) must be of type DateTimeImmutable, null given, called in /application/vendor/symfony/scheduler/Generator/MessageGenerator.php on line 81 at /application/vendor/symfony/scheduler/Trigger/JitterTrigger.php:32)"} []

How to reproduce

I suppose this should be easy to reproduce by using a 'frequency' that overlaps the 'until' parameter in combination with some 'jitter':

#[AsPeriodicTask(frequency: '30 minutes', from: '06:00 Europe/Amsterdam', until: '23:50 Europe/Amsterdam', jitter: 120, arguments: null, schedule: 'default')]

Possible Solution

Not exactly sure what the root cause is. I guess that MessageGenerator::getMessages() assumes that JitterTrigger::getNextRunDate() always returns a DateTimeImmutable and not null.

Additional Context

I have not seen this issue with Symfony 7.2.x

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions