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)
69 lines
2.7 KiB
C#
69 lines
2.7 KiB
C#
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;
|
|
|
|
namespace ECMJobRunner.Application.Profiles.Commands
|
|
{
|
|
/// <summary>
|
|
/// Command to trigger a single DEX job execution
|
|
/// Execution logic is handled by pipeline behaviors:
|
|
/// 1. MainQueryExecutionBehavior - executes main SQL query
|
|
/// 2. CheckQueryExecutionBehavior - validates with check SQL query
|
|
/// 3. ReCRequestExecutionBehavior - invokes ReC HTTP request
|
|
/// </summary>
|
|
public class TriggeringProfileJobCommand : IRequest<Unit>
|
|
{
|
|
/// <summary>
|
|
/// The SQL job to execute
|
|
/// </summary>
|
|
public ProfileSqlJob Job { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Unique batch identifier for this execution
|
|
/// </summary>
|
|
public string BatchId { get; set; } = null!;
|
|
|
|
internal BatchRecActionViewResponse? RecActionResult { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for TriggeringDEXJobCommand
|
|
/// All execution logic is delegated to pipeline behaviors
|
|
/// This handler simply returns completion after behaviors execute
|
|
/// </summary>
|
|
public class TriggeringDEXJobCommandHandler(ISender Sender) : IRequestHandler<TriggeringProfileJobCommand, Unit>
|
|
{
|
|
/// <summary>
|
|
/// Handles the TriggeringDEXJobCommand
|
|
/// Returns immediately as behaviors perform all work
|
|
/// </summary>
|
|
/// <param name="request">The command containing job and batch ID</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Unit value indicating completion</returns>
|
|
public async Task<Unit> Handle(TriggeringProfileJobCommand request, CancellationToken cancellationToken)
|
|
{
|
|
// All execution logic is handled by pipeline behaviors:
|
|
// - MainQueryExecutionBehavior
|
|
// - CheckQueryExecutionBehavior
|
|
// - ReCRequestExecutionBehavior
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|