You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that there are steps where you can't get an object from the database because it may not already exist and this logic is repeated in different steps.
The solutions I see are:
Make typed exceptions so that you can distinguish them in OnStepError and call host.TerminateWorkflow(workflowId);
Create a step, for example RecordNotFoundStep and use it after each it is required. But this is not convenient, as another developer needs to understand where this step is required, and the workflow configuration will look like something messy.
Ideal solution: have it possible to call a step that will execute and the workflow will finish.
publicclass RequestBuffersStep(
ISender mediator,
IMarkingDbContext dbContext,ILogger? logger =default):StepBodyAsync{publicintOrganizationId{ get; set;}publicoverrideasyncTask<ExecutionResult>RunAsync(IStepExecutionContextcontext){varquery=new GetOrganizationQuery(OrganizationId: OrganizationId);vargetOrganizationResponse=await mediator.Send(query).ConfigureAwait(false);// If there is an error when trying to get the organization from the databaseif(getOrganizationResponse.IsError){await SetErrorMessageToOrderAndThrowExceptionAsync(getOrganizationResponse.FirstError.Description,
context.CancellationToken);}varorganization= getOrganizationResponse.Value;// ...return ExecutionResult.Next();}privateasync Task SetErrorMessageToOrderAndThrowExceptionAsync(stringmessage,CancellationTokencancellationToken){varorder=await dbContext.Orders.Where(o => o.Id == OrderData.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);if(order isnull){
logger?.Error("Order with ID {Id} not found in database.", OrderData.Id);thrownew Exception($"Order with ID {OrderData.Id} not found in database.");// throw exception and terminate workflow in OnStepError}varerror=new Error(message);
order.SetError(error);await dbContext.SaveChangesAsync(cancellationToken);thrownew Exception(message);// throw exception and terminate workflow in OnStepError}}
The text was updated successfully, but these errors were encountered:
The problem is that there are steps where you can't get an object from the database because it may not already exist and this logic is repeated in different steps.
The solutions I see are:
Ideal solution: have it possible to call a step that will execute and the workflow will finish.
The text was updated successfully, but these errors were encountered: