Skip to content

[Scheduler] Not working triggers with OS datetime different from PHP setting #50764

@davidromani

Description

@davidromani

Symfony version(s) affected

6.3.0

Description

I've prepared a scheduled every 2 minutes task with the following code:

<?php

namespace App\Schedule\Provider;

use App\Message\UpdateGoogleAnalyticsVisitsMessage;
use Symfony\Component\Scheduler\Attribute\AsSchedule;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\Schedule;
use Symfony\Component\Scheduler\ScheduleProviderInterface;

#[AsSchedule('default')]
class DefaultScheduleProvider implements ScheduleProviderInterface
{
    public function getSchedule(): Schedule
    {
        return (new Schedule())->add(
            RecurringMessage::every(
                '120 seconds',
                new MyUpdateManagerMessage()
            )
        );
    }
}

Then I've opened a consumer with Supervisor but it seem that there is some divergenge between OS clock & PHP process clock that never fires the recurring message.

How to reproduce

With the corresponding MyUpdateManagerMessage & MyUpdateManagerMessageHandler classes created. If you execute the console debug command:

# /usr/bin/php8.2 bin/console debug:scheduler --env=prod

Scheduler
=========

default
-------

 ------------------------------------ -------------------------------------- --------------------------- 
  Message                              Trigger                                Next Run                   
 ------------------------------------ -------------------------------------- --------------------------- 
  MyUpdateManagerMessage               PeriodicalTrigger: every 120 seconds   2023-06-24T07:11:34+00:00  
 ------------------------------------ -------------------------------------- --------------------------- 

Take a look at the "Next Run" date created. Then I've check my OS date & it seems that is configured 2 hours later (probably due to my timezone).

# date
Sat Jun 24 09:11:56 CEST 2023

If you open a foreground console process every thing works well, and I can see the message fired every 2 minutes as I expected.

# /usr/bin/php8.2 bin/console messenger:consume scheduler_default -vv

But If I decide to open it as a background process managed by Supervisor, the same command is never fired. May be is due to the timezone difference? The "Next Run" date is never achieved because is a 2 hours in past moment.

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