Skip to content

Commit

Permalink
Merge pull request #720 from themsaid/completedJobsTrimming
Browse files Browse the repository at this point in the history
[3.x] Allow trimming completed jobs
  • Loading branch information
taylorotwell authored Feb 14, 2020
2 parents 0f45a70 + 8356f5a commit f0295ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/horizon.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

'trim' => [
'recent' => 60,
'completed' => 60,
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
Expand Down
10 changes: 9 additions & 1 deletion src/Repositories/RedisJobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit f0295ee

Please sign in to comment.