Skip to content

Commit

Permalink
Auto Check Db for incomplete tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 27, 2024
1 parent 7a17de0 commit 013c4b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions MyApp.ServiceInterface/JobServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ public object Any(ViewModelQueues request)
};
}

public object Any(GetNextJobs request)
public async Task<object> 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<PostJob>()
.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 }
Expand Down

0 comments on commit 013c4b6

Please sign in to comment.