From dd9e6a710bc23d0da5f6904d9cdc6a4711534cf3 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 4 Aug 2026 16:34:30 +0200 Subject: [PATCH] feat(history): add ProfileHistory creation with job execution results TriggeringProfileJobCommand: - Add RecActionResult property to store ReC action execution results - Convert handler to primary constructor with ISender injection - Create ProfileHistory after successful job execution - Include detailed execution metrics in history (TotalActionCount, ActionExceptionCount, BatchId) - Add required using statements for ProfileHistories and ValueObjects ProfileWorkerOptionsValidator: - Fix XML documentation reference to ValidateOptionsResult.Fail(string) --- .../Commands/TriggeringProfileJobCommand.cs | 25 ++++++++++++++++--- .../ProfileWorker/DependencyInjection.cs | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ECMJobRunner.Application/Profiles/Commands/TriggeringProfileJobCommand.cs b/ECMJobRunner.Application/Profiles/Commands/TriggeringProfileJobCommand.cs index dfb4bdd..b594f0e 100644 --- a/ECMJobRunner.Application/Profiles/Commands/TriggeringProfileJobCommand.cs +++ b/ECMJobRunner.Application/Profiles/Commands/TriggeringProfileJobCommand.cs @@ -1,5 +1,9 @@ -using ECMJobRunner.Domain.Entities; +using ECMJobRunner.Application.ProfileHistories.Commands; +using ECMJobRunner.Domain.Entities; +using ECMJobRunner.Domain.Interfaces; +using ECMJobRunner.Domain.ValueObjects; using MediatR; +using ReC.Client.Api; using System.Threading; using System.Threading.Tasks; @@ -23,6 +27,8 @@ namespace ECMJobRunner.Application.Profiles.Commands /// Unique batch identifier for this execution /// public string BatchId { get; set; } = null!; + + internal BatchRecActionViewResponse? RecActionResult { get; set; } } /// @@ -30,7 +36,7 @@ namespace ECMJobRunner.Application.Profiles.Commands /// All execution logic is delegated to pipeline behaviors /// This handler simply returns completion after behaviors execute /// - public class TriggeringDEXJobCommandHandler : IRequestHandler + public class TriggeringDEXJobCommandHandler(ISender Sender) : IRequestHandler { /// /// Handles the TriggeringDEXJobCommand @@ -39,13 +45,24 @@ namespace ECMJobRunner.Application.Profiles.Commands /// The command containing job and batch ID /// Cancellation token /// Unit value indicating completion - public Task Handle(TriggeringProfileJobCommand request, CancellationToken cancellationToken) + public async Task Handle(TriggeringProfileJobCommand request, CancellationToken cancellationToken) { // All execution logic is handled by pipeline behaviors: // - MainQueryExecutionBehavior // - CheckQueryExecutionBehavior // - ReCRequestExecutionBehavior - return Task.FromResult(Unit.Value); + + var cmd = new CreateProfileHistoryCommand + { + Result = ResultType.Ok, + ResultText = $"Job '{request.Job.Name}' erfolgreich abgeschlossen. | Batch-ID: {request.BatchId} | Verarbeitete Aktionen: {request.RecActionResult?.TotalActionCount ?? 0} | Fehlgeschlagene Aktionen: {request.RecActionResult?.ActionExceptionCount ?? 0}", + ProfileId = request.Job.ProfileId, + AddedWho = "ECMJobRunner" + }; + + await Sender.Send(cmd, cancellationToken); + + return Unit.Value; } } } diff --git a/ECMJobRunner.WebCron/ProfileWorker/DependencyInjection.cs b/ECMJobRunner.WebCron/ProfileWorker/DependencyInjection.cs index 0bd4778..b83adc0 100644 --- a/ECMJobRunner.WebCron/ProfileWorker/DependencyInjection.cs +++ b/ECMJobRunner.WebCron/ProfileWorker/DependencyInjection.cs @@ -55,7 +55,7 @@ internal class ProfileWorkerOptionsValidator : IValidateOptionsThe options to validate. /// /// if valid, - /// or with error message if invalid. + /// or with error message if invalid. /// /// /// Validation rules: