Skip to content

Commit

Permalink
Some refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
bsandmann committed Feb 3, 2025
1 parent eedd946 commit 8f67692
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Blocktrust.CredentialWorkflow.Core.Commands.Workflow.ExecuteWorkflow;
using Tenant.GetPrivateIssuingKeyByDid;
using WorkflowOutcome.UpdateWorkflowOutcome;

public class ExecuteWorkflowHandler : IRequestHandler<ExecuteWorkflowRequest, Result>
public class ExecuteWorkflowHandler : IRequestHandler<ExecuteWorkflowRequest, Result<bool>>
{
private readonly IMediator _mediator;

Expand All @@ -30,7 +30,7 @@ public ExecuteWorkflowHandler(IMediator mediator)
_mediator = mediator;
}

public async Task<Result> Handle(ExecuteWorkflowRequest request, CancellationToken cancellationToken)
public async Task<Result<bool>> Handle(ExecuteWorkflowRequest request, CancellationToken cancellationToken)
{
var workflowId = request.WorkflowOutcome.WorkflowId;
var workflowOutcomeId = request.WorkflowOutcome.WorkflowOutcomeId;
Expand Down Expand Up @@ -126,7 +126,7 @@ public async Task<Result> Handle(ExecuteWorkflowRequest request, CancellationTok
return await FinishActionsWithSuccess(workflowOutcomeId, actionOutcomes, cancellationToken);
}

private async Task<Result> FinishActionsWithSuccess(Guid workflowOutcomeId, List<ActionOutcome> actionOutcomes, CancellationToken cancellationToken)
private async Task<Result<bool>> FinishActionsWithSuccess(Guid workflowOutcomeId, List<ActionOutcome> actionOutcomes, CancellationToken cancellationToken)
{
var workflowUpdateResult = await _mediator.Send(
new UpdateWorkflowOutcomeRequest(
Expand All @@ -137,11 +137,11 @@ private async Task<Result> FinishActionsWithSuccess(Guid workflowOutcomeId, List
return Result.Fail("The workflow outcome could not be updated.");
}

return Result.Ok();
return Result.Ok(true);
}


private async Task<Result> FinishActionsWithFailure(Guid worflowOutcomeId, ActionOutcome actionOutcome, string errorMessage, List<ActionOutcome> actionOutcomes, CancellationToken cancellationToken)
private async Task<Result<bool>> FinishActionsWithFailure(Guid worflowOutcomeId, ActionOutcome actionOutcome, string errorMessage, List<ActionOutcome> actionOutcomes, CancellationToken cancellationToken)
{
actionOutcome.FinishOutcomeWithFailure(errorMessage);
actionOutcomes.Add(actionOutcome);
Expand All @@ -154,7 +154,7 @@ private async Task<Result> FinishActionsWithFailure(Guid worflowOutcomeId, Actio
return Result.Fail("The workflow outcome could not be updated.");
}

return Result.Ok();
return Result.Ok(false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Blocktrust.CredentialWorkflow.Core.Commands.Workflow.ExecuteWorkflow;
using FluentResults;
using MediatR;

public class ExecuteWorkflowRequest : IRequest<Result>
public class ExecuteWorkflowRequest : IRequest<Result<bool>>
{
public ExecuteWorkflowRequest(WorkflowOutcome workflowOutcome)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,11 @@ await mediator.Send(
stoppingToken
);

// Update the outcome state
if (executeResult.IsSuccess)
if (executeResult.IsFailed)
{
// This is a critial error
await mediator.Send(
new UpdateWorkflowOutcomeRequest(outcomeId, EWorkflowOutcomeState.Success, outcomeJson: null, null),
stoppingToken
);
}
else
{
await mediator.Send(
new UpdateWorkflowOutcomeRequest(outcomeId, EWorkflowOutcomeState.FailedWithErrors, outcomeJson: null, executeResult.Errors.FirstOrDefault()?.Message),
new UpdateWorkflowOutcomeRequest(outcomeId, EWorkflowOutcomeState.FailedWithErrors, outcomeJson: null, $"Fatal processing error: {executeResult.Errors.FirstOrDefault()?.Message}"),
stoppingToken
);
}
Expand Down
10 changes: 9 additions & 1 deletion Blocktrust.CredentialWorkflow.Web/Components/Pages/Log.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<tbody>
@foreach (var workflowOutcome in workflowOutcomes)
{
<tr @onclick="() => ToggleOutcomeDetails(workflowOutcome.WorkflowId)"
<tr @onclick="() => ToggleOutcomeDetails(workflowOutcome.WorkflowOutcomeId)"
class="cursor-pointer hover:bg-gray-50 transition-colors duration-150">
<td class="border-t px-4 py-2">
<span class="@GetOutcomeStateColor(workflowOutcome.WorkflowOutcomeState)">
Expand All @@ -72,6 +72,10 @@
<strong>ActionWorkflowOutcome
JSON:</strong> @(string.IsNullOrEmpty(workflowOutcome.ActionOutcomesJson) ? "N/A" : workflowOutcome.ActionOutcomesJson)
</p>
<p>
<strong>Execution Context
</strong> @(string.IsNullOrEmpty(workflowOutcome.ExecutionContext) ? "N/A" : workflowOutcome.ExecutionContext)
</p>
}
else if (workflowOutcome.WorkflowOutcomeState == EWorkflowOutcomeState.NotStarted)
{
Expand All @@ -87,6 +91,10 @@
<strong>Error
JSON:</strong> @(string.IsNullOrEmpty(workflowOutcome.ErrorJson) ? "N/A" : workflowOutcome.ErrorJson)
</p>
<p>
<strong>Execution Context
</strong> @(string.IsNullOrEmpty(workflowOutcome.ExecutionContext) ? "N/A" : workflowOutcome.ExecutionContext)
</p>
}
</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion Blocktrust.CredentialWorkflow.Web/WorkflowTriggers.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GET https://localhost:7209/api/workflow/22222222-2222-2222-2222-222222222222
&testClaim=RandomStringABC

### POST request to WorkflowController with JSON body
POST https://localhost:7209/api/workflow/f16e63e7-2478-4c8a-7063-08dd447e7f75
POST https://localhost:7209/api/workflow/c8a4d381-c060-4e5d-0940-08dd448c10c5
Content-Type: application/json

{
Expand Down

0 comments on commit 8f67692

Please sign in to comment.