Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
-
How can I compose a single Schedule from different places in code through some kind of extension points? My use case is that:
The "convenience" attributes This defines the #[AsSchedule('foo')]class FooScheduleimplements ScheduleProviderInterface{privateSchedule$schedule;publicfunctiongetSchedule() :Schedule {return$this->schedule ??= (newSchedule()) ->with( RecurringMessage::every('10 seconds',newFooMessage('Hello'), ) ); }} Now, in a different service, I would like to add another trigger to the existing schedule. I tried two approaches:
#[AsSchedule('foo')]class ExtendingScheduleimplements ScheduleProviderInterface{privateSchedule$schedule;publicfunctiongetSchedule() :Schedule {return$this->schedule ??= (newSchedule()) ->with( RecurringMessage::every('20 seconds',newFooMessage('Extended hello'), ) ); }} This does not work (as could be expected) and only one of the duplicate
class SomeService{publicfunction__construct(FooSchedule$fooSchedule, ) {$fooSchedule->getSchedule()->add( RecurringMessage::every('20 seconds',newFooMessage('Extended hello')) ); }} This results in:
Looking at the
My So, given that these do not work, what is the recommended and supported way of composing schedules? I have scoured the documentation and all the examples I have come across only show a simplistic case where the schedule is defined in one class. I am thinking that I could collect all the "extending services" myself through custom tags and autowiring in the Schedule class, but it feels there should be a more out-of-the-box way to do that. Thank you |
BetaWas this translation helpful?Give feedback.
All reactions
👀 1
Replies: 2 comments 1 reply
-
But you can just write |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks for the answer, though there are some more issues with this that I should have expanded on in the question. We have a containerized deployment, one of the containers is currently the "scheduler" and runs
I think what I am missing from the documentation (this is not throwing blame) is what the best practice is. Is it expected that each logical "feature" has its own schedule with even just one or two tasks and the workers consume many different transports? Or is it recommended to have fewer large schedules (e.g. one with a lock and stateful for large tasks, one for quick tasks)? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I ran into this myself today and decided to create a command that implements approach (2) from@melkamar's list:https://gist.github.com/rpander93/609ac5e429827577cacf79ddb7f58e22 |
BetaWas this translation helpful?Give feedback.