Skip to content

[Scheduler] messages won't run, "Next run" always adds the interval to current time #58124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BentiGorlich opened this issue Aug 29, 2024 · 7 comments

Comments

@BentiGorlich
Copy link

Symfony version(s) affected

7.1.1

Description

When running the command php bin/console debug:scheduler I get this output:

Scheduler
=========

default
-------

 ---------------- -------------------------------------- --------------------------------- 
  Trigger          Provider                               Next Run                         
 ---------------- -------------------------------------- --------------------------------- 
  every 1 day      App\Message\ClearDeletedUserMessage    Fri, 30 Aug 2024 19:39:55 +0000  
  every 1 minute   App\Message\ClearDeadMessagesMessage   Thu, 29 Aug 2024 19:40:55 +0000  
 ---------------- -------------------------------------- --------------------------------- 

The "Next Run" column will always show the current time plus the interval, ergo the messages are not running

How to reproduce

Add a default schedule:

#[AsSchedule]
class DeleteUserTaskProvider implements ScheduleProviderInterface
{
    private ?Schedule $schedule = null;

    public function __construct(
        private readonly CacheInterface $cache
    ) {
    }

    public function getSchedule(): Schedule
    {
        if (null === $this->schedule) {
            $this->schedule = (new Schedule())
                ->add(
                    RecurringMessage::every('1 day', new ClearDeletedUserMessage()),
                    RecurringMessage::every('1 minute', new ClearDeadMessagesMessage())
                )
                ->stateful($this->cache);
        }
        return $this->schedule;
    }
}

The message classes are just empty ones. I already tried generating the schedule with the make:schedul command, same result

Possible Solution

No response

Additional Context

I added a schedule and 2 messages, one that runs every day and a new one that runs every minute, because I noticed that the job isn't running, so I wanted to debug it

@n0rbyt3
Copy link
Contributor

n0rbyt3 commented Aug 30, 2024

Did you consume the messages at least once?
php bin/console messenger:consume scheduler_default

Your cache will store the last execution time which defaults to now if no value is found. You can also check the presence of the scheduler_checkpoint_default key.

@BentiGorlich
Copy link
Author

Yes I have a messenger consume running with the scheduler_default queue. I saw it creating the checkpoint once though the behaviour still persisted

@n0rbyt3
Copy link
Contributor

n0rbyt3 commented Aug 31, 2024

I had a look at the code. It's by design. The debug:scheduler command always uses the passed date (--date option) to calculate the next run. If you skip the argument, now is used by default.

The real scheduling process uses the SchedulerTransportFactory to create a SchedulerTransport which holds a MessageGeneratorInterface that reads the checkpoint value to calculate the next run.

So it's not a bug but may be a feature to extend the debug:scheduler command to support a special date argument last-run which also uses the SchedulerTransportFactory to calculate the next run.

@BentiGorlich
Copy link
Author

The Handler for the ClearDeadMessagesMessage that should run every minute only contains a logger call, but I do not see any thing logged in the messenger output... So it is not running...

@xabbuh
Copy link
Member

xabbuh commented Aug 31, 2024

Can you create a small example application that allows to reproduce your issue?

@xabbuh
Copy link
Member

xabbuh commented Sep 13, 2024

I am going to close here for now due to the lack of feedback. Please let us know when you have more information and we can consider to reopen.

@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2024
@BentiGorlich
Copy link
Author

I am sorry, I have no idea how to setup this kind of project. I know it is a problem we have in the mbin project. Maybe you can try to look at that project? https://github.com/MbinOrg/mbin/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants