Job qui enlève les vieilles jobRun
All checks were successful
Push image to registry / build-image (push) Successful in 6m18s
All checks were successful
Push image to registry / build-image (push) Successful in 6m18s
This commit is contained in:
35
app/Jobs/PruneOldJobRuns.php
Normal file
35
app/Jobs/PruneOldJobRuns.php
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user