Skip to content

Commit cad36cb

Browse files
fix: scan Redis for all job keys in overview endpoint
Overview endpoint now scans all job metrics keys in Redis and aggregates total_processed and total_failed across all job classes instead of trying to use wildcards. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4ca3587 commit cad36cb

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

.claude/settings.local.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
"mcp__serena__write_memory",
3636
"WebFetch(domain:divinglaravel.com)",
3737
"WebFetch(domain:medium.com)",
38-
"WebFetch(domain:stackoverflow.com)"
38+
"WebFetch(domain:stackoverflow.com)",
39+
"Bash(composer update:*)",
40+
"Bash(php:*)",
41+
"Bash(timeout 30 php:*)",
42+
"Bash(curl:*)"
3943
],
4044
"deny": [],
4145
"ask": []

src/Services/MetricsQueryService.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,32 @@ public function getOverview(): array
9090
$queues = $this->queueMetricsRepository->listQueues();
9191
$workers = $this->workerRepository->getActiveWorkers();
9292

93-
// Aggregate job counts from all discovered queues
93+
// Aggregate job counts from all job metrics keys in Redis
9494
$totalProcessed = 0;
9595
$totalFailed = 0;
9696

97-
foreach ($queues as $queueInfo) {
98-
$connection = $queueInfo['connection'];
99-
$queue = $queueInfo['queue'];
100-
101-
// Get all job classes for this queue and sum their metrics
102-
$metrics = $this->jobMetricsRepository->getMetrics('*', $connection, $queue);
103-
$totalProcessed += (int) ($metrics['total_processed'] ?? 0);
104-
$totalFailed += (int) ($metrics['total_failed'] ?? 0);
97+
// Scan Redis for all job metrics keys and aggregate
98+
$pattern = config('database.redis.options.prefix', '') . config('queue-metrics.storage.prefix') . ':jobs:*';
99+
$driver = app(\PHPeek\LaravelQueueMetrics\Storage\StorageManager::class)->driver();
100+
101+
// Get all job metrics keys
102+
$keys = [];
103+
$cursor = '0';
104+
do {
105+
$result = $driver->scanKeys($pattern);
106+
if (is_array($result)) {
107+
$keys = array_merge($keys, $result);
108+
break;
109+
}
110+
} while (false);
111+
112+
// Sum metrics from all keys
113+
foreach ($keys as $key) {
114+
$data = $driver->getHash($key);
115+
if (is_array($data)) {
116+
$totalProcessed += (int) ($data['total_processed'] ?? 0);
117+
$totalFailed += (int) ($data['total_failed'] ?? 0);
118+
}
105119
}
106120

107121
return [

0 commit comments

Comments
 (0)