Closed
Description
Symfony version(s) affected
6.4
Description
According to the documentation at:
https://symfony.com/doc/current/scheduler.html#a-strategic-event-handling
Using those functions like that does not work and results in a 500 error
{"message":"Uncaught Error: Call to a member function addListener() on null","context":{"exception":{"class":"Error","message":"Call to a member function addListener() on null","code":0,"file":"/app/vendor/symfony/scheduler/Schedule.php:144"}},"channel":"php","extra":{},"severity":"CRITICAL","time":"2024-02-01T13:22:04.559+01:00"}
How to reproduce
// ...
public function getSchedule(): Schedule
{
$this->schedule ??= (new Schedule())
->with(...$this->getGeneralMessages(), ...$this->getProductionMessages())
->before(function (PreRunEvent $event) {
$this->logger?->info('Before Event');
})
->after(function (PostRunEvent $event) {
$this->logger?->info('After Event');
})
->onFailure(function (FailureEvent $event) {
$this->logger?->info('Failure Event');
$this->logger?->info($event->getError()->getMessage());
})
->lock($this->lockFactory->createLock('cron-cache'))
->stateful($this->cache);
return $this->schedule;
}
Possible Solution
Either update documentaiton, add error handling and throw our own exception or fail silently and log an error?
Additional Context
No response