feat(application): add inactive profile validation with custom exception
- Create InactiveProfileException for profile active status validation - Update TriggeringDEXJobBatchCommand to check profile active status before execution - Add ICfgProfileRepository dependency to batch command handler - Throw InactiveProfileException when attempting to execute inactive profiles - Add profile not found validation with descriptive error message - Reorganize commands under DEXJob/Commands directory structure
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
using ECMJobRunner.Domain.Interfaces;
|
||||
using ECMJobRunner.Application.Common.Exceptions;
|
||||
using ECMJobRunner.Application.Common.Interfaces;
|
||||
using ECMJobRunner.Domain.Interfaces;
|
||||
using MediatR;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ECMJobRunner.Application.DEXJob
|
||||
namespace ECMJobRunner.Application.DEXJob.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Command to trigger DEX job batch for a profile
|
||||
@@ -21,8 +23,9 @@ namespace ECMJobRunner.Application.DEXJob
|
||||
/// <summary>
|
||||
/// Handler for TriggeringDEXJobBatchCommand
|
||||
/// Retrieves all SQL jobs for a profile and executes them sequentially
|
||||
/// Validates that the profile is active before execution
|
||||
/// </summary>
|
||||
public class TriggeringDEXJobBatchCommandHandler(IProfileSqlJobRepository jobRepo, ISender sender)
|
||||
public class TriggeringDEXJobBatchCommandHandler(ICfgProfileRepository profileRepo, IProfileSqlJobRepository jobRepo, ISender sender)
|
||||
: IRequestHandler<TriggeringDEXJobBatchCommand, Unit>
|
||||
{
|
||||
/// <summary>
|
||||
@@ -32,12 +35,28 @@ namespace ECMJobRunner.Application.DEXJob
|
||||
/// <param name="request">The command containing the profile ID</param>
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
/// <returns>Unit value indicating completion</returns>
|
||||
/// <exception cref="InactiveProfileException">Thrown when the profile is not active</exception>
|
||||
public async Task<Unit> Handle(TriggeringDEXJobBatchCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var jobs = await jobRepo.FindAsync(j => j.ProfileId == request.ProfileId, cancellationToken);
|
||||
|
||||
var batchId = CreateBatchId();
|
||||
|
||||
// Retrieve the profile to check if it's active
|
||||
var profile = await profileRepo.GetByIdAsync(request.ProfileId, cancellationToken);
|
||||
|
||||
// Check if profile exists and is active
|
||||
if (profile == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Profile with ID {request.ProfileId} not found.");
|
||||
}
|
||||
|
||||
if (!profile.Active)
|
||||
{
|
||||
throw new InactiveProfileException(profile.Id, profile.ProfileName, batchId);
|
||||
}
|
||||
|
||||
// Retrieve all jobs for the profile
|
||||
var jobs = await jobRepo.FindAsync(j => j.ProfileId == request.ProfileId, cancellationToken);
|
||||
|
||||
foreach (var job in jobs)
|
||||
{
|
||||
await sender.Send(new TriggeringDEXJobCommand
|
||||
@@ -3,7 +3,7 @@ using MediatR;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ECMJobRunner.Application.DEXJob
|
||||
namespace ECMJobRunner.Application.DEXJob.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Command to trigger a single DEX job execution
|
||||
Reference in New Issue
Block a user