1 | <?php |
||
10 | class ProcessorInterfaceAdapter implements ProcessorInterface |
||
11 | { |
||
12 | use |
||
13 | EventDispatcherAware, |
||
14 | MessageAdapterFactoryAware, |
||
15 | MessageProcessorAware; |
||
16 | |||
17 | private |
||
18 | $workerContext; |
||
19 | |||
20 | 5 | public function __construct(WorkerContext $workerContext) |
|
26 | |||
27 | 5 | public function process(\Swarrot\Broker\Message $message, array $options) |
|
28 | { |
||
29 | 5 | $message = $this->createMessageAdapter($message); |
|
30 | 5 | $message = $this->onConsume($message); |
|
31 | |||
32 | 5 | $this->workerContext->getLogger()->debug((string) $message); |
|
33 | |||
34 | 5 | $this->onWorkerProcess(); |
|
35 | |||
36 | try |
||
37 | { |
||
38 | 5 | $processResult = $this->workerContext->getWorker()->process($message); |
|
39 | } |
||
40 | 2 | catch(\Throwable $exception) |
|
41 | { |
||
42 | 2 | $this->onWorkerProcessed(); |
|
43 | |||
44 | 2 | if($exception instanceof \Error) |
|
45 | { |
||
46 | 1 | $exception = new \ErrorException($exception->getMessage(), $exception->getCode(), E_ERROR, $exception->getFile(), $exception->getLine(), $exception); |
|
47 | } |
||
48 | |||
49 | 2 | throw $exception; |
|
50 | } |
||
51 | |||
52 | 3 | $this->onWorkerProcessed(); |
|
53 | |||
54 | 3 | return $processResult; |
|
55 | } |
||
56 | |||
57 | 5 | private function onWorkerProcess() |
|
61 | |||
62 | 5 | private function onWorkerProcessed() |
|
66 | } |
||
67 |