From df431e533a70e5892c6f8af32e37be7c7b5c6d79 Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 28 Jun 2025 20:18:28 +0200 Subject: [PATCH] Add POST Jobs/Cleaup Endpoint: Removes failed and completed Jobs (that are not recurring) --- API/Controllers/JobController.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/API/Controllers/JobController.cs b/API/Controllers/JobController.cs index 712e3c3..49609f5 100644 --- a/API/Controllers/JobController.cs +++ b/API/Controllers/JobController.cs @@ -374,4 +374,25 @@ public class JobController(PgsqlContext context, ILog Log) : Controller { return StatusCode(Status501NotImplemented); } + + /// + /// Removes failed and completed Jobs (that are not recurring) + /// + /// Job started + /// Error during Database Operation + [HttpPost("Cleanup")] + public IActionResult CleanupJobs() + { + try + { + context.Jobs.RemoveRange(context.Jobs.Where(j => j.state == JobState.Failed || j.state == JobState.Completed)); + context.SaveChanges(); + return Ok(); + } + catch (Exception e) + { + Log.Error(e); + return StatusCode(500, e.Message); + } + } } \ No newline at end of file