Total Complexity | 5 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class PcntlSignalDispatchSubscriber implements EventSubscriberInterface |
||
13 | { |
||
14 | public static function getSubscribedEvents() |
||
19 | ]; |
||
20 | } |
||
21 | |||
22 | public function __construct(Consumer $consumer) |
||
23 | { |
||
24 | $stopConsumer = function () use ($consumer) { |
||
25 | // Process current message, then halt consumer |
||
26 | $consumer->forceStopConsumer(); |
||
27 | // Halt consumer if waiting for a new message from the queue |
||
28 | try { |
||
29 | $consumer->stopConsuming(true); |
||
30 | } catch (AMQPTimeoutException $e) {} |
||
|
|||
31 | }; |
||
32 | |||
33 | pcntl_signal(SIGTERM, $stopConsumer); |
||
34 | pcntl_signal(SIGINT, $stopConsumer); |
||
35 | // TODO pcntl_signal(SIGHUP, $restartConsumer); |
||
36 | } |
||
37 | |||
38 | public function onConsume(OnConsumeEvent $event) |
||
39 | { |
||
40 | pcntl_signal_dispatch(); |
||
41 | } |
||
42 | |||
43 | public function afterProcessingMessages(AfterProcessingMessagesEvent $event) |
||
46 | } |
||
47 | } |