Event listeners should have a simple way to invoke code in a job, without the need to implement and register a dedicated job class.
Implementation idea: if we register subscriber objects by name, we can define a generic job class that is constructed around the name of the subscriber and the name of a method to call on that subscriber. When executed, the job will ask the event dispatcher for the subscriber by name, then invoke the method. With the appropriate support in EventSubscriberBase, this will allow listeners to schedule any method on the subscriber for execution via a job:
MySubscriber extends EventSubscriberBase { public function handleFooEvent ( FooEvent $event ) { if ( !$event->isInteresting() ) { return; } $this->schduleCall( 'doSlowStuffWithFooEvent', $event ); } public function doSlowStuffWithFooEvent( FooEvent $event ) { // slow stuff } }
Note that this supercededs T384609: Domain Events: support listener invocation via the job queue: Executing the listener itself via the job queue is ineffecient and provides too little control. We'd schedule at least one job per event that has subscribers using the in-job invocation mode, but probably more: using one job per listener is better for retry behavior and if we need to re-route specific jobs/handlers to a separate stream or even a dedicated cluster. This seems inefficient, since current usage patterns in hook handlers show that the actual business logic will only be execute in a small subset of cases - for most events, the handler exists early. So it would be more sensible to only shedule a job if we already know that the business logic should actually run.