-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathQueueCollector.php
More file actions
108 lines (90 loc) · 2.42 KB
/
Copy pathQueueCollector.php
File metadata and controls
108 lines (90 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Debug;
use Yiisoft\Queue\MessageStatus;
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface;
use Yiisoft\Queue\Message\MessageInterface;
use function count;
final class QueueCollector implements SummaryCollectorInterface
{
use CollectorTrait;
/**
* @var array[]
*/
private array $pushes = [];
private array $statuses = [];
/**
* @var array[]
*/
private array $processingMessages = [];
public function getCollected(): array
{
if (!$this->isActive()) {
return [];
}
return [
'pushes' => $this->pushes,
'statuses' => $this->statuses,
'processingMessages' => $this->processingMessages,
];
}
public function collectStatus(string $id, MessageStatus $status, string $line): void
{
if (!$this->isActive()) {
return;
}
$this->statuses[] = [
'id' => $id,
'status' => $status->key(),
'line' => $line,
];
}
public function collectPush(string $queueName, MessageInterface $message, string $line): void
{
if (!$this->isActive()) {
return;
}
$this->pushes[$queueName][] = [
'message' => $message,
'line' => $line,
];
}
public function collectWorkerProcessing(MessageInterface $message, string $queueName): void
{
if (!$this->isActive()) {
return;
}
$this->processingMessages[$queueName][] = $message;
}
public function getSummary(): array
{
if (!$this->isActive()) {
return [];
}
$countPushes = array_sum(
array_map(
count(...),
$this->pushes,
),
);
$countStatuses = count($this->statuses);
$countProcessingMessages = array_sum(
array_map(
count(...),
$this->processingMessages,
),
);
return [
'countPushes' => $countPushes,
'countStatuses' => $countStatuses,
'countProcessingMessages' => $countProcessingMessages,
];
}
private function reset(): void
{
$this->pushes = [];
$this->statuses = [];
$this->processingMessages = [];
}
}