| @@ 140-173 (lines=34) @@ | ||
| 137 | * |
|
| 138 | * @return mixed |
|
| 139 | */ |
|
| 140 | public function execute($action, array $payload) |
|
| 141 | { |
|
| 142 | $executor = $this->executorPool->getExecutor($action); |
|
| 143 | ||
| 144 | // dispatch pre event, listeners may change the payload here |
|
| 145 | $event = new ExecutionEvent($executor, $action, $payload); |
|
| 146 | $this->dispatcher->dispatch(WorkerEvents::PRE_EXECUTE_ACTION, $event); |
|
| 147 | ||
| 148 | try { |
|
| 149 | $resolver = $this->getPayloadResolver($executor); |
|
| 150 | $payload = $resolver->resolve($event->getPayload()); |
|
| 151 | } catch (ExceptionInterface $exception) { |
|
| 152 | $this->logger->error( |
|
| 153 | sprintf( |
|
| 154 | 'Payload %s for "%s" is invalid: %s', |
|
| 155 | json_encode($payload, JSON_UNESCAPED_SLASHES), |
|
| 156 | $action, |
|
| 157 | $exception->getMessage() |
|
| 158 | ) |
|
| 159 | ); |
|
| 160 | ||
| 161 | return false; |
|
| 162 | } |
|
| 163 | ||
| 164 | $result = $executor->execute($payload); |
|
| 165 | ||
| 166 | $event = clone $event; |
|
| 167 | ||
| 168 | // dispatch post event, listeners may change the result here |
|
| 169 | $event->setResult($result); |
|
| 170 | $this->dispatcher->dispatch(WorkerEvents::POST_EXECUTE_ACTION, $event); |
|
| 171 | ||
| 172 | return $event->getResult(); |
|
| 173 | } |
|
| 174 | ||
| 175 | /** |
|
| 176 | * Returns a cached version of the payload resolver for an executor. |
|
| @@ 549-579 (lines=31) @@ | ||
| 546 | * |
|
| 547 | * @return mixed |
|
| 548 | */ |
|
| 549 | public function execute($action, array $payload) |
|
| 550 | { |
|
| 551 | $executor = $this->getExecutor($action); |
|
| 552 | ||
| 553 | // dispatch pre event, listeners may change the payload here |
|
| 554 | $event = new ExecutionEvent($executor, $action, $payload); |
|
| 555 | $this->dispatcher->dispatch(WorkerEvents::PRE_EXECUTE_ACTION, $event); |
|
| 556 | ||
| 557 | try { |
|
| 558 | $resolver = $this->getPayloadResolver($executor); |
|
| 559 | $payload = $resolver->resolve($event->getPayload()); |
|
| 560 | } catch (ExceptionInterface $exception) { |
|
| 561 | $this->logger->error( |
|
| 562 | sprintf( |
|
| 563 | 'Payload %s for "%s" is invalid: %s', |
|
| 564 | json_encode($payload, JSON_UNESCAPED_SLASHES), |
|
| 565 | $action, |
|
| 566 | $exception->getMessage() |
|
| 567 | ) |
|
| 568 | ); |
|
| 569 | ||
| 570 | return false; |
|
| 571 | } |
|
| 572 | ||
| 573 | $result = $executor->execute($payload); |
|
| 574 | // dispatch post event, listeners may change the result here |
|
| 575 | $event->setResult($result); |
|
| 576 | $this->dispatcher->dispatch(WorkerEvents::POST_EXECUTE_ACTION, $event); |
|
| 577 | ||
| 578 | return $event->getResult(); |
|
| 579 | } |
|
| 580 | ||
| 581 | /** |
|
| 582 | * CAUTION: this removes all items from an action's queue. |
|