From 013c4b6a948b7a0cc7c486b599ee2783355bcbb8 Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Wed, 27 Mar 2024 12:32:54 +0800 Subject: [PATCH] Auto Check Db for incomplete tasks --- MyApp.ServiceInterface/JobServices.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MyApp.ServiceInterface/JobServices.cs b/MyApp.ServiceInterface/JobServices.cs index 101c3c3..0555625 100644 --- a/MyApp.ServiceInterface/JobServices.cs +++ b/MyApp.ServiceInterface/JobServices.cs @@ -16,12 +16,24 @@ public object Any(ViewModelQueues request) }; } - public object Any(GetNextJobs request) + public async Task Any(GetNextJobs request) { var to = new GetNextJobsResponse(); var job = workerQueues.Dequeue(request.Models, TimeSpan.FromSeconds(30)); if (job == null) - return to; + { + var dbHasIncompleteJobs = await Db.SelectAsync(Db.From() + .Where(x => x.CompletedDate == null || x.StartedDate < DateTime.UtcNow.AddMinutes(-5))); + if (dbHasIncompleteJobs.Count > 0) + { + await Any(new RestoreModelQueues { RestoreFailedJobs = true }); + job = workerQueues.Dequeue(request.Models, TimeSpan.FromSeconds(30)); + } + if (job == null) + { + return to; + } + } MessageProducer.Publish(new DbWrites { StartJob = new() { Id = job.Id, Worker = request.Worker, WorkerIp = Request!.RemoteIp }