Skip to content

Commit 1ec2f5c

Browse files
fix: Avoid Filtering Failed Jobs Timestamp in Memory (#193)
* fix: Avoid Filtering Failed Jobs Timestamp in Memory To display queue metrics, Vapor loads all `failed_jobs` and filters the period (1m, 5m, 10m, 30m, 1h, 24h, 7d, 30d) in memory. When the failed_jobs table has a large number of rows, usually as a result of not pruning failed_jobs on a regular-basis, it would cause Queue Metrics to fail with HTTP status 502. `getTable` was made public via laravel/framework#56384 Note: In another PR, we could also filter all the other filter options (id, queue, query) * Update VaporQueueListFailedCommand.php --------- Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
1 parent 72121dc commit 1ec2f5c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Console/Commands/VaporQueueListFailedCommand.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,26 @@ class VaporQueueListFailedCommand extends Command
4343
*/
4444
public function handle()
4545
{
46-
$failed = $this->laravel['queue.failer']->all();
47-
4846
$options = collect($this->options())
4947
->filter(function ($value, $option) {
5048
return ! is_null($value) && in_array($option, ['id', 'queue', 'query', 'start']);
5149
});
5250

51+
$failer = $this->laravel['queue.failer'];
52+
$start = $this->option('start');
53+
54+
if (is_callable([$failer, 'getTable']) && $start) {
55+
$failed = $failer->getTable()
56+
->where('failed_at', '>=', Carbon::createFromTimestamp($start)->toDateTimeString())
57+
->get();
58+
59+
$options = $options->reject(function ($value, $name) {
60+
return $name === 'start';
61+
});
62+
} else {
63+
$failed = $failer->all();
64+
}
65+
5366
$failedJobs = collect($failed)->filter(function ($job) use ($options) {
5467
return $options->every(function ($value, $option) use ($job) {
5568
return $this->filter($job, $option, $value);

0 commit comments

Comments
 (0)