Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle queue size when using multiple queues #35

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
3 changes: 3 additions & 0 deletions config/filament-jobs-monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
'enabled' => true,
'retention_days' => 7,
],
'queues' => [
'default'
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ 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 [
Stat::make(__('filament-jobs-monitor::translations.total_jobs'), $aggregatedInfo->count ?? 0),
Stat::make(__('filament-jobs-monitor::translations.pending_jobs'), Queue::size()),
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),
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),
];
}
}