From 8356f5af4513987d56246e2478d55e41d7abc73f Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 9 Dec 2019 08:18:33 +0200 Subject: [PATCH] allow trimming completed jobs --- config/horizon.php | 1 + src/Repositories/RedisJobRepository.php | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/horizon.php b/config/horizon.php index b9803a88..ee5ae3a1 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -95,6 +95,7 @@ 'trim' => [ 'recent' => 60, + 'completed' => 60, 'recent_failed' => 10080, 'failed' => 10080, 'monitored' => 10080, diff --git a/src/Repositories/RedisJobRepository.php b/src/Repositories/RedisJobRepository.php index bfb72877..2350e252 100644 --- a/src/Repositories/RedisJobRepository.php +++ b/src/Repositories/RedisJobRepository.php @@ -42,6 +42,13 @@ class RedisJobRepository implements JobRepository */ public $recentJobExpires; + /** + * The number of minutes until completed jobs should be purged. + * + * @var int + */ + public $recentCompletedExpires; + /** * The number of minutes until failed jobs should be purged. * @@ -66,6 +73,7 @@ public function __construct(RedisFactory $redis) { $this->redis = $redis; $this->recentJobExpires = config('horizon.trim.recent', 60); + $this->recentCompletedExpires = config('horizon.trim.completed', 60); $this->failedJobExpires = config('horizon.trim.failed', 10080); $this->recentFailedJobExpires = config('horizon.trim.recent_failed', $this->failedJobExpires); $this->monitoredJobExpires = config('horizon.trim.monitored', 10080); @@ -403,7 +411,7 @@ protected function markJobAsCompleted($pipe, $id, $failed) ? $pipe->hmset($id, ['status' => 'failed']) : $pipe->hmset($id, ['status' => 'completed', 'completed_at' => str_replace(',', '.', microtime(true))]); - $pipe->expireat($id, Chronos::now()->addMinutes($this->recentJobExpires)->getTimestamp()); + $pipe->expireat($id, Chronos::now()->addMinutes($this->recentCompletedExpires)->getTimestamp()); } /**