connectholland/tactician-prioritycommand-plugin

This package is abandoned and no longer maintained. No replacement package was suggested.

Tactician plugin that allows adding a priority to a command which influences when and in what order commands will be executed

0.2.0 2016-04-04 13:04 UTC

This package is auto-updated.

Last update: 2023-05-29 00:49:41 UTC


README

Tactician plugin that allows adding a priority to a command which influences when and in what order commands will be executed

Build Status Coverage Status SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version License

Concept

The plugin adds Middleware that allows you to prioritize your commands. To give priority to a command let it extend from one of the command implementations in this library:

Default supported command types:

  • AbstractRequestCommand (bus, you may take a detour, but you may not start a new round)
  • AbstractSequenceCommand (bus, you may take a detour, but nobody gets off before I do)
  • AbstractUrgentCommand (take me to my destination asap)

You can create an interface to your event dispatcher (one for symfony ships with this library). You should attach the PriorityMiddleware::REQUEST queue to some event you always dispatch, preferably after output is sent to your users.

Suggested priorities

Obviously you're free to give your commands any priority you like, but these guidelines may help:

  • Urgent: anything that affects the output you send to your user OR anything that affects the behavior of incoming request
  • Request: anything that affects any subsequent requests from your user
  • Sequence: anything that affects the behavior of following commands (i.e. because it sets an id in your database something else depends on)

Issues

Commands are not executed immediately which makes it impossible to return values. If you rely on the return value of a command, you can't make that command a priority command without breaking your application. The fix for this is to add an event listener before putting the command on the bus and dispatching an event from the handler which passes the return value. Example, code with return value

$result = $commandbus->handle($command);
echo "The result is.... {$result}";

Without the return value:

$eventdispatcher->addListener('when_my_commandhandler_is_done', function($event) {
    echo "The result is.... {$event->getReturnValue()}";
});
$result = $commandbus->handle($priorityCommand);