Skip to content

Commit

Permalink
readd lost jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 25, 2024
1 parent 5c78e8d commit 2b75581
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MyApp.ServiceInterface/JobServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public object Any(RestoreModelQueues request)
var incompleteJobs = Db.Select(Db.From<PostJob>().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);
Expand All @@ -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",
]
};
}
Expand Down

0 comments on commit 2b75581

Please sign in to comment.