Search code examples
laravellaravel-horizonhorizon

Silenced jobs not cleared correctly


I've got a batch of silenced jobs (+/- 7k every hour), which are running correctly and completed. Normally the completed jobs are cleared after 1 hour, but the silenced jobs are standing in Redis for 7 days. This seems a bit odd to me and it's taking up a lot of space in Redis.

Horizon Config:

/*
    |--------------------------------------------------------------------------
    | Job Trimming Times
    |--------------------------------------------------------------------------
    |
    | Here you can configure for how long (in minutes) you desire Horizon to
    | persist the recent and failed jobs. Typically, recent jobs are kept
    | for one hour while all failed jobs are stored for an entire week.
    |
    */

    'trim' => [
        'recent' => 60,
        'pending' => 60,
        'completed' => 60,
        'recent_failed' => 10080,
        'failed' => 10080,
        'monitored' => 10080,
    ],

Job:

class ClearCategorySkusJob implements ShouldBeUnique, ShouldQueue, Silenced {
    use Dispatchable, Queueable;

    public int $tries = 3;

    public function __construct(
        private readonly string $category,
        private readonly string $domain,
    ) {
        $this->onQueue('cache');
    }

    public function handle(): void {}
    
    public function uniqueId(): string {}

    public function tags(): array {}

}
  • PHP version: 8.2.26
  • Redis version: 6.2.13
  • Laravel version: 10.48.24
  • Horizon version: 5.24.3

Solution

  • Our silenced jobs where monitored by a tag, and because the time for a monitored job to clear was 7 days, the silenced jobs where saved for 7 days. See the provided config, where monitored is set to 10080.

    Normally a silenced job will be taken care of the same as a normal job, so normally it will be deleted in 1 day.

    We deleted the monitor, so the silenced jobs went back to normal again.