From ce13d1b0dd16cf5b23217c4412d90a979958a913 Mon Sep 17 00:00:00 2001 From: Matthias Guillitte Date: Thu, 27 Feb 2025 18:54:40 +0100 Subject: [PATCH] =?UTF-8?q?Job=20qui=20enl=C3=A8ve=20les=20vieilles=20jobR?= =?UTF-8?q?un?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Jobs/PruneOldJobRuns.php | 35 +++++++++++++++++++++++++++++++++++ config/jobs.php | 20 ++++++++++++++++++++ routes/console.php | 7 ++++++- todo.md | 4 ++-- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 app/Jobs/PruneOldJobRuns.php create mode 100644 config/jobs.php diff --git a/app/Jobs/PruneOldJobRuns.php b/app/Jobs/PruneOldJobRuns.php new file mode 100644 index 0000000..fd7c7b4 --- /dev/null +++ b/app/Jobs/PruneOldJobRuns.php @@ -0,0 +1,35 @@ +jobRuns() + ->orderByDesc('id') + ->skip(config('jobs.pruneOldJobRuns.max_runs_per_job')) + ->delete(); + } + } +} diff --git a/config/jobs.php b/config/jobs.php new file mode 100644 index 0000000..0457368 --- /dev/null +++ b/config/jobs.php @@ -0,0 +1,20 @@ + [ + 'enabled' => true, + + /** + * How many job runs a job can keep before we start pruning old ones. + */ + 'max_runs_per_job' => 50, + ], + +]; diff --git a/routes/console.php b/routes/console.php index df5d44c..3d242da 100644 --- a/routes/console.php +++ b/routes/console.php @@ -1,7 +1,7 @@ monthly(); +// Prune old job runs +Schedule::job(new PruneOldJobRuns)->monthly()->onOneServer()->withoutOverlapping()->name('prune-old-job-runs')->description('Prune old job runs')->skip(function () { + return !config('jobs.pruneOldJobRuns.enabled'); +}); + // Jobs Schedule::job(new HellcaseJob)->daily()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job'); // Schedule::job(new HellcaseJob)->everyMinute()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job'); diff --git a/todo.md b/todo.md index 0367887..4343e98 100644 --- a/todo.md +++ b/todo.md @@ -7,10 +7,10 @@ - → Notification - Ou ajouter des images base64 dans les jobRun - Risque de devenir volumineux - - Sauf avec le jobqui enlève les vieilles jobRun + - Sauf avec le job qui enlève les vieilles jobRun - Notification live websocket + - Websocket installé - Serveur php plus propre (nginx, apache, n'importe) -- Job qui supprime les vieilles JobRun - Epic games ## Pour deploy Lama