Job qui enlève les vieilles jobRun
All checks were successful
Push image to registry / build-image (push) Successful in 6m18s

This commit is contained in:
2025-02-27 18:54:40 +01:00
parent a80a32eee8
commit ce13d1b0dd
4 changed files with 63 additions and 3 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace App\Jobs;
use App\Models\Job;
use App\Models\JobRun;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class PruneOldJobRuns implements ShouldQueue
{
use Queueable;
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
// For each job, keep only the last N runs
foreach (Job::all() as $job) {
$job->jobRuns()
->orderByDesc('id')
->skip(config('jobs.pruneOldJobRuns.max_runs_per_job'))
->delete();
}
}
}