1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Collector; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Yii\Queue\Message\MessageInterface; |
8
|
|
|
use Yiisoft\Yii\Queue\QueueInterface; |
9
|
|
|
|
10
|
|
|
final class QueueCollector implements CollectorInterface, IndexCollectorInterface |
11
|
|
|
{ |
12
|
|
|
use CollectorTrait; |
13
|
|
|
|
14
|
|
|
private array $pushes = []; |
15
|
|
|
private array $statuses = []; |
16
|
|
|
private array $processingMessages = []; |
17
|
|
|
|
18
|
1 |
|
public function getCollected(): array |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
1 |
|
'pushes' => $this->pushes, |
22
|
1 |
|
'statuses' => $this->statuses, |
23
|
1 |
|
'processingMessages' => $this->processingMessages, |
24
|
|
|
]; |
25
|
|
|
} |
26
|
|
|
|
27
|
1 |
|
public function collectStatus(string $id): void |
28
|
|
|
{ |
29
|
1 |
|
if (!$this->isActive()) { |
30
|
|
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
$this->statuses[] = $id; |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function collectPush(string $channel, MessageInterface $message): void |
37
|
|
|
{ |
38
|
1 |
|
if (!$this->isActive()) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
1 |
|
$this->pushes[$channel][] = $message; |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
public function collectWorkerProcessing(MessageInterface $message, QueueInterface $queue) |
45
|
|
|
{ |
46
|
1 |
|
if (!$this->isActive()) { |
47
|
|
|
return; |
48
|
|
|
} |
49
|
1 |
|
$this->processingMessages[$queue->getChannelName()][] = $message; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
private function reset(): void |
|
|
|
|
53
|
|
|
{ |
54
|
1 |
|
$this->pushes = []; |
55
|
1 |
|
$this->statuses = []; |
56
|
1 |
|
$this->processingMessages = []; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
public function getIndexData(): array |
60
|
|
|
{ |
61
|
1 |
|
$countPushes = array_sum(array_map(fn ($messages) => count($messages), $this->pushes)); |
62
|
1 |
|
$countStatuses = count($this->statuses); |
63
|
1 |
|
$countProcessingMessages = array_sum(array_map(fn ($messages) => count($messages), $this->processingMessages)); |
64
|
|
|
|
65
|
|
|
return [ |
66
|
|
|
'queue' => [ |
67
|
|
|
'countPushes' => $countPushes, |
68
|
|
|
'countStatuses' => $countStatuses, |
69
|
|
|
'countProcessingMessages' => $countProcessingMessages, |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.