Skip to content

Commit

Permalink
Added timeout command for Incidents Batch Resolution saga
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Feb 6, 2024
1 parent 0af596e commit e2c7c8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static WolverineOptions ConfigureIncidents(this WolverineOptions options)
rule.MessagesImplementing<IncidentsBatchResolutionEvent>();
rule.Message<TimeoutIncidentsBatchResolution>();
rule
.ToLocalQueue("incidents_batch_resolution")
.UseDurableInbox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DateTimeOffset now
commands.AddRange(incidents.Select(incidentId =>
new ResolveIncidentFromBatch(incidentId, agentId, resolutionType, batchId))
);
commands.Add(new TimeoutIncidentsBatchResolution(batchId).DelayedFor(1.Minutes()));

return (
new CreationResponse($"/api/incidents/resolution/{batchId}?version=1"),
Expand All @@ -43,12 +44,22 @@ DateTimeOffset now
? Handle(batch, @event.IncidentId, ResolutionStatus.Failed, now)
: [];

[AggregateHandler]
public static Events Handle(TimeoutIncidentsBatchResolution command, IncidentsBatchResolution batch,
DateTimeOffset now) =>
batch.Status != ResolutionStatus.Pending
? [new IncidentsBatchResolutionResolutionTimedOut(command.IncidentsBatchResolutionId, batch.Incidents, now)]
: [];

private static Events Handle(
IncidentsBatchResolution batch,
Guid incidentId,
ResolutionStatus status,
DateTimeOffset now)
{
if (batch.Status != ResolutionStatus.Pending || batch.Incidents[incidentId] != ResolutionStatus.Pending)
return [];

object recorded = status == ResolutionStatus.Resolved
? new IncidentResolutionRecorded(incidentId, batch.Id, now)
: new IncidentResolutionFailureRecorded(incidentId, batch.Id, now);
Expand Down Expand Up @@ -77,3 +88,7 @@ public record InitiateIncidentsBatchResolution(
Guid AgentId,
ResolutionType ResolutionType
);

public record TimeoutIncidentsBatchResolution(
Guid IncidentsBatchResolutionId
);

0 comments on commit e2c7c8a

Please sign in to comment.