From 2eb59f92d46e090e05f5aeb54bb59a96b957a5f8 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sun, 10 Mar 2024 07:49:47 +0100 Subject: [PATCH 1/2] handle queue size when using multiple queues --- README.md | 5 +++++ config/filament-jobs-monitor.php | 3 +++ .../QueueMonitorResource/Widgets/QueueStatsOverview.php | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23e49fc..ffebb03 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,14 @@ return [ 'enabled' => true, 'retention_days' => 7, ], + 'queues' => [ + 'default' + ], ]; ``` +**NOTE:** Since there isn't a universal way to retrieve all used queues, it's necessary to define them to obtain all pending jobs. + ### Extending Model Sometimes it's useful to extend the model to add some custom methods. You can do it by extending the model by creating your own model : diff --git a/config/filament-jobs-monitor.php b/config/filament-jobs-monitor.php index 585a61e..c154e75 100644 --- a/config/filament-jobs-monitor.php +++ b/config/filament-jobs-monitor.php @@ -15,4 +15,7 @@ 'enabled' => true, 'retention_days' => 7, ], + 'queues' => [ + 'default' + ], ]; diff --git a/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php b/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php index a6dd5b8..3a9186f 100644 --- a/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php +++ b/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php @@ -22,9 +22,13 @@ protected function getCards(): array ->select($aggregationColumns) ->first(); + $queueSize = collect(config('filament-jobs-monitor.queues') ?? ['default']) + ->map(fn(string $queue): int => Queue::size($queue)) + ->sum(); + return [ Card::make(__('filament-jobs-monitor::translations.total_jobs'), $aggregatedInfo->count ?? 0), - Card::make(__('filament-jobs-monitor::translations.pending_jobs'), Queue::size()), + Card::make(__('filament-jobs-monitor::translations.pending_jobs'), $queueSize), Card::make(__('filament-jobs-monitor::translations.execution_time'), ($aggregatedInfo->total_time_elapsed ?? 0).'s'), Card::make(__('filament-jobs-monitor::translations.average_time'), ceil((float) $aggregatedInfo->average_time_elapsed).'s' ?? 0), ]; From a6c7260f4b4aa4e81e762a9f6f7e4650731f3583 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Thu, 4 Jul 2024 11:31:14 +0200 Subject: [PATCH 2/2] feat: use Stat instead of deprecated Card --- .../Widgets/QueueStatsOverview.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php b/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php index 3a9186f..ebfa86a 100644 --- a/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php +++ b/src/Resources/QueueMonitorResource/Widgets/QueueStatsOverview.php @@ -4,7 +4,7 @@ use Croustibat\FilamentJobsMonitor\Models\QueueMonitor; use Filament\Widgets\StatsOverviewWidget as BaseWidget; -use Filament\Widgets\StatsOverviewWidget\Card; +use Filament\Widgets\StatsOverviewWidget\Stat; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Queue; @@ -27,10 +27,10 @@ protected function getCards(): array ->sum(); return [ - Card::make(__('filament-jobs-monitor::translations.total_jobs'), $aggregatedInfo->count ?? 0), - Card::make(__('filament-jobs-monitor::translations.pending_jobs'), $queueSize), - Card::make(__('filament-jobs-monitor::translations.execution_time'), ($aggregatedInfo->total_time_elapsed ?? 0).'s'), - Card::make(__('filament-jobs-monitor::translations.average_time'), ceil((float) $aggregatedInfo->average_time_elapsed).'s' ?? 0), + Stat::make(__('filament-jobs-monitor::translations.total_jobs'), $aggregatedInfo->count ?? 0), + Stat::make(__('filament-jobs-monitor::translations.pending_jobs'), $queueSize), + Stat::make(__('filament-jobs-monitor::translations.execution_time'), ($aggregatedInfo->total_time_elapsed ?? 0) . 's'), + Stat::make(__('filament-jobs-monitor::translations.average_time'), ceil((float) $aggregatedInfo->average_time_elapsed) . 's' ?? 0), ]; } }