Skip to content

Latest commit

 

History

History
73 lines (55 loc) · 2.48 KB

event_dispatcher_task.md

File metadata and controls

73 lines (55 loc) · 2.48 KB

EventDispatcherTask

Dispatches a CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent through the Symfony event dispatcher. The event gives listeners access to the current ProcessState (getState()), so they can read the input and, when the task is not passive, set the output themselves.

Task reference

  • Service: CleverAge\ProcessBundle\Task\Event\EventDispatcherTask
  • Code: event_dispatcher (task: event_dispatcher)

Accepted inputs

any

Possible outputs

  • any: the input, unchanged, when passive is true
  • when passive is false: whatever a listener set with $event->getState()->setOutput(), null otherwise

Options

Code Type Required Default Description
event_name string|null null Name of the dispatched event, null to use the event class name (see Notes)
passive bool true If true, the input is passed to the output before dispatch

Examples

  • Dispatch an event for each item
# Task configuration level
data:
  task: constant_iterable_output
  options:
    output: [1, 2, 3]
  outputs: [push_data_event]
push_data_event:
  task: event_dispatcher
  options:
    event_name: myapp.data_queue

Notes

The event is dispatched with $eventDispatcher->dispatch($event, $eventName):

  • when event_name is set, listeners must subscribe to that name:
#[AsEventListener(event: 'myapp.data_queue')]
public function onDataQueue(EventDispatcherTaskEvent $event): void
{
    $input = $event->getState()->getInput();
}
  • when event_name is null, the event name is the event class name, so listeners must subscribe to CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent. Every EventDispatcherTask without event_name then triggers the same listeners.

Since v6.0, an event dispatched under its event_name is no longer dispatched under its class name too: the listeners of CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent are only called by the tasks without event_name. From v4.0 to v5.x, they were also called (deprecated since 5.1) when event_name was set: listen to the configured event_name instead, or remove the event_name option.