From 2b755816f643e4d6f1d16c1c0df70b41fdd17e9c Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Mon, 25 Mar 2024 16:14:24 +0800 Subject: [PATCH] readd lost jobs --- MyApp.ServiceInterface/JobServices.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MyApp.ServiceInterface/JobServices.cs b/MyApp.ServiceInterface/JobServices.cs index e49e680..ea77318 100644 --- a/MyApp.ServiceInterface/JobServices.cs +++ b/MyApp.ServiceInterface/JobServices.cs @@ -39,7 +39,13 @@ public object Any(RestoreModelQueues request) var incompleteJobs = Db.Select(Db.From().Where(x => x.CompletedDate == null)); var missingJobs = incompleteJobs.Where(x => !pendingJobIds.Contains(x.Id) && x.StartedDate == null).ToList(); var startedJobs = incompleteJobs.Where(x => x.StartedDate != null).ToList(); + var lostJobsBefore = DateTime.UtcNow.Add(TimeSpan.FromMinutes(-5)); + var lostJobs = startedJobs.Where(x => x.StartedDate < lostJobsBefore && missingJobs.All(m => m.Id != x.Id)).ToList(); + foreach (var lostJob in lostJobs) + { + workerQueues.Enqueue(lostJob); + } foreach (var missingJob in missingJobs) { workerQueues.Enqueue(missingJob); @@ -51,7 +57,7 @@ public object Any(RestoreModelQueues request) $"{pendingJobs.Count} pending jobs in queue", $"{incompleteJobs.Count} incomplete jobs in database", $"{startedJobs.Count} jobs being processed by workers", - $"{missingJobs.Count} jobs missing and re-added to queue", + $"{missingJobs.Count} missing and ${lostJobs.Count} lost jobs re-added to queue", ] }; }