Replies: 2 comments 2 replies
-
But you can just write |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How can I compose a single Schedule from different places in code through some kind of extension points?
My use case is that:
bin/console messenger:consume scheduler_NAMEworker running. I want to keep the infrastructure simple without running many different workers.The "convenience" attributes
#[AsPeriodicTask]and#[AsCronTask]do what I am looking for - they add new triggers to the schedule. However, I couldn't find a way to be able to add new triggers through "rich" PHP code where more customization can be made. See code below.This defines the
fooschedule with a single trigger:Now, in a different service, I would like to add another trigger to the existing schedule. I tried two approaches:
#[AsSchedule]attribute.This does not work (as could be expected) and only one of the duplicate
fooschedules will be registered - the other is completely ignored.FooSchedulein a service. This one I thought should work, but I get container build errors.This results in:
Looking at the
FooScheduleclass, which is registered as a service, I see that it is overwritten in the container and assigned a different class!My
FooScheduleis hidden behind a decorator (I think) and the DI fails.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
Beta Was this translation helpful? Give feedback.
All reactions