1 | <?php |
||
13 | class RabbitMQRequirementListener |
||
14 | { |
||
15 | protected $processStatus; |
||
16 | protected $queueHistory; |
||
17 | protected $admin; |
||
18 | protected $logger; |
||
19 | |||
20 | /** |
||
21 | * Set process status handler |
||
22 | * |
||
23 | * @param ProcessStatusHandler $handler |
||
24 | */ |
||
25 | 12 | public function setProcessStatusHandler(ProcessStatusHandler $handler) |
|
29 | |||
30 | /** |
||
31 | * Set the queue history object to help retrieve last |
||
32 | * queue depth number |
||
33 | * |
||
34 | * @param HistoryInterface $history |
||
35 | */ |
||
36 | 12 | public function setQueueHistory(HistoryInterface $history) |
|
40 | |||
41 | /** |
||
42 | * Set the rabbitmq admin interface |
||
43 | * |
||
44 | * @param Admin $admin |
||
45 | */ |
||
46 | 12 | public function setRabbitMQAdmin(Admin $admin) |
|
50 | |||
51 | /** |
||
52 | * Set the logger |
||
53 | * |
||
54 | * @param LoggerInterface $logger |
||
55 | */ |
||
56 | public function setLogger(LoggerInterface $logger) |
||
60 | |||
61 | /** |
||
62 | * Compute how many consumers needs to be run |
||
63 | * |
||
64 | * @param ProvisionRequirementEvent $event |
||
65 | */ |
||
66 | 6 | public function handle(ProvisionRequirementEvent $event) |
|
137 | |||
138 | /** |
||
139 | * Determine how many consumers to launch based on previous |
||
140 | * messages count and the new one, and the available consumers |
||
141 | * |
||
142 | * @param float $previousDepth |
||
143 | * @param float $currentDepth |
||
144 | * @param int $messages Messages consumed by one consumer |
||
145 | * @param int $consumers Running consumers |
||
146 | * |
||
147 | * @return int |
||
148 | */ |
||
149 | 6 | public function computeRequirement($previousDepth, $currentDepth, $messages, $consumers) |
|
184 | |||
185 | /** |
||
186 | * Return estimated previous and current depth once |
||
187 | * a linear regression is applied to the real history |
||
188 | * |
||
189 | * @param array $history |
||
190 | * |
||
191 | * @return array As ['previous' => float, 'current' => float] |
||
192 | */ |
||
193 | 3 | public function getEstimatedDepth(array $history) |
|
205 | } |
||
206 |