|
@@ -1,6 +1,8 @@
|
|
|
using Quadarax.Application.QLiberace.Base.Services;
|
|
using Quadarax.Application.QLiberace.Base.Services;
|
|
|
|
|
+using Quadarax.Application.QLiberace.Common.Executor;
|
|
|
using Quadarax.Application.QLiberace.Processor.Entities;
|
|
using Quadarax.Application.QLiberace.Processor.Entities;
|
|
|
using Quadarax.Application.QLiberace.Processor.Enums;
|
|
using Quadarax.Application.QLiberace.Processor.Enums;
|
|
|
|
|
+using Quadarax.Application.QLiberace.Processor.Executor;
|
|
|
using Quadarax.Application.QLiberace.Processor.Repositories;
|
|
using Quadarax.Application.QLiberace.Processor.Repositories;
|
|
|
using Quadarax.Application.QLiberace.Processor.Settings;
|
|
using Quadarax.Application.QLiberace.Processor.Settings;
|
|
|
using Quadarax.Foundation.Core.Business;
|
|
using Quadarax.Foundation.Core.Business;
|
|
@@ -30,34 +32,61 @@ namespace Quadarax.Application.QLiberace.Processor.Workers
|
|
|
|
|
|
|
|
#region *** Private Operations ***
|
|
#region *** Private Operations ***
|
|
|
|
|
|
|
|
- protected override Task DoIteration(IWorkerContext context)
|
|
|
|
|
|
|
+ protected override async Task DoIteration(IWorkerContext context)
|
|
|
{
|
|
{
|
|
|
var ctx = (RepoWorkerContext)context;
|
|
var ctx = (RepoWorkerContext)context;
|
|
|
- // Get worker name
|
|
|
|
|
- var workerName = GetName(Settings.ProcessingWorkerPwi);
|
|
|
|
|
-
|
|
|
|
|
- var repoProcessing = ctx.GetRepository<RepoProcessingQueue>();
|
|
|
|
|
-
|
|
|
|
|
- // 1. Continue to work on already processing entries in ProcessQ (paused, tryout failed)
|
|
|
|
|
- // 2. If still available packet, lock pending entries in PendingQ
|
|
|
|
|
- // 3. Move locked entries to ProcessQ
|
|
|
|
|
- var processings = FetchFromQueue(ctx.GetRepository<RepoPendingQueue>(), ctx.GetRepository<RepoProcessingQueue>());
|
|
|
|
|
-
|
|
|
|
|
- foreach (var processing in processings)
|
|
|
|
|
- {
|
|
|
|
|
- processing.Started = DateTime.Now;
|
|
|
|
|
- processing.AffinityWorker = workerName;
|
|
|
|
|
- processing.Status = QueueStatusEnum.Working;
|
|
|
|
|
- repoProcessing.Set(processing);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- // 4. Start to process
|
|
|
|
|
- // 5. Decrement attempt
|
|
|
|
|
- // 6. Move processed entries to DoneQ or FailedQ
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // Get worker name
|
|
|
|
|
+ var workerName = GetName(Settings.ProcessingWorkerPwi);
|
|
|
|
|
+
|
|
|
|
|
+ var repoProcessing = ctx.GetRepository<RepoProcessingQueue>();
|
|
|
|
|
+ var repoData = ctx.GetRepository<RepoQueueData>();
|
|
|
|
|
+ var repoDone = ctx.GetRepository<RepoDoneQueue>();
|
|
|
|
|
+
|
|
|
|
|
+ // 1. Continue to work on already processing entries in ProcessQ (paused, tryout failed)
|
|
|
|
|
+ // 2. If still available packet, lock pending entries in PendingQ
|
|
|
|
|
+ // 3. Move locked entries to ProcessQ
|
|
|
|
|
+ var processing = FetchFromQueue(ctx.GetRepository<RepoPendingQueue>(), ctx.GetRepository<RepoProcessingQueue>());
|
|
|
|
|
+
|
|
|
|
|
+ foreach (var processItem in processing)
|
|
|
|
|
+ {
|
|
|
|
|
+ processItem.Started = DateTime.Now;
|
|
|
|
|
+ processItem.AffinityWorker = workerName;
|
|
|
|
|
+ processItem.AttemptLeft -= 1;
|
|
|
|
|
+ processItem.Status = QueueStatusEnum.Working;
|
|
|
|
|
+ repoProcessing.Set(processItem);
|
|
|
|
|
+
|
|
|
|
|
+ var dataList = repoData.GetQueueData(processItem.Id).ToArray();
|
|
|
|
|
+ var paramList = dataList.Select(x => (ParameterExecutorValue)x.ToParametrizedValue()).ToArray();
|
|
|
|
|
+
|
|
|
|
|
+ var exe = new ExecutorInternal(processItem, paramList);
|
|
|
|
|
+ var result = exe.Execute(Timeout, _logger);
|
|
|
|
|
+ if (result.IsSuccess)
|
|
|
|
|
+ {
|
|
|
|
|
+ //success
|
|
|
|
|
+ //update modified output values (from Execute)
|
|
|
|
|
+ foreach (var parOutput in paramList.Where(x => x.IsOutput))
|
|
|
|
|
+ {
|
|
|
|
|
+ repoData.UpdateQueueData(processItem.Id, parOutput.Code, parOutput.Value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var done = repoDone.NewFromProcessing(processItem);
|
|
|
|
|
+ done.Status = QueueStatusEnum.Success;
|
|
|
|
|
+ processItem.Status = QueueStatusEnum.Deleted;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //failed
|
|
|
|
|
+ if (processItem.AttemptLeft == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ //move to failed
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ // next tryout
|
|
|
|
|
+ processItem.Status = QueueStatusEnum.Assigned;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|