@atolis-hq/wake 0.3.33 → 0.3.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,48 +16,42 @@ export class DeliveryOutcomeReactor {
|
|
|
16
16
|
async runOnce() {
|
|
17
17
|
const consumer = 'reactor:delivery-outcomes';
|
|
18
18
|
const events = await this.journal.readAll(await this.checkpoints.load(consumer));
|
|
19
|
+
const resolvedDeliveryEventIds = new Set();
|
|
19
20
|
for (const event of events) {
|
|
20
|
-
|
|
21
|
-
if (delivery !== null) {
|
|
22
|
-
const command = {
|
|
23
|
-
workflowInstanceId: workflowInstanceId(delivery.payload.workflowInstanceId),
|
|
24
|
-
activationId: activationId(delivery.payload.activationId),
|
|
25
|
-
};
|
|
26
|
-
if (await this.isAwaitingThisDelivery(command, delivery.payload.intentEventId)) {
|
|
27
|
-
if (delivery.eventType === DeliveryEventType.Confirmed ||
|
|
28
|
-
(delivery.eventType === DeliveryEventType.Reconciled &&
|
|
29
|
-
delivery.payload.result === DeliveryResultKind.Confirmed))
|
|
30
|
-
await this.orchestration.acceptOutcome({
|
|
31
|
-
...command,
|
|
32
|
-
outcome: {
|
|
33
|
-
kind: ActivityOutcomeKind.Done,
|
|
34
|
-
data: { deliveryEventId: delivery.eventId },
|
|
35
|
-
},
|
|
36
|
-
}, {
|
|
37
|
-
commandId: delivery.eventId,
|
|
38
|
-
correlationId: event.correlationId,
|
|
39
|
-
actor: { kind: EventActorKind.System, id: 'delivery-outcome-reactor' },
|
|
40
|
-
occurredAt: event.recordedAt,
|
|
41
|
-
});
|
|
42
|
-
if (delivery.eventType === DeliveryEventType.Failed)
|
|
43
|
-
await this.orchestration.acceptOutcome({
|
|
44
|
-
...command,
|
|
45
|
-
outcome: {
|
|
46
|
-
kind: ActivityOutcomeKind.Failed,
|
|
47
|
-
data: { reason: delivery.payload.code },
|
|
48
|
-
},
|
|
49
|
-
}, {
|
|
50
|
-
commandId: delivery.eventId,
|
|
51
|
-
correlationId: event.correlationId,
|
|
52
|
-
actor: { kind: EventActorKind.System, id: 'delivery-outcome-reactor' },
|
|
53
|
-
occurredAt: event.recordedAt,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
21
|
+
await this.reconcile(event, resolvedDeliveryEventIds);
|
|
57
22
|
await this.checkpoints.save(consumer, event.globalPosition);
|
|
58
23
|
}
|
|
24
|
+
for (const event of await this.journal.readAll(0))
|
|
25
|
+
await this.reconcile(event, resolvedDeliveryEventIds);
|
|
59
26
|
return events.length;
|
|
60
27
|
}
|
|
28
|
+
async reconcile(event, seen) {
|
|
29
|
+
const delivery = selectDeliveryEvent(event);
|
|
30
|
+
if (delivery === null || seen.has(delivery.eventId))
|
|
31
|
+
return;
|
|
32
|
+
const outcome = delivery.eventType === DeliveryEventType.Confirmed ||
|
|
33
|
+
(delivery.eventType === DeliveryEventType.Reconciled &&
|
|
34
|
+
delivery.payload.result === DeliveryResultKind.Confirmed)
|
|
35
|
+
? { kind: ActivityOutcomeKind.Done, data: { deliveryEventId: delivery.eventId } }
|
|
36
|
+
: delivery.eventType === DeliveryEventType.Failed
|
|
37
|
+
? { kind: ActivityOutcomeKind.Failed, data: { reason: delivery.payload.code } }
|
|
38
|
+
: null;
|
|
39
|
+
if (outcome === null)
|
|
40
|
+
return;
|
|
41
|
+
const command = {
|
|
42
|
+
workflowInstanceId: workflowInstanceId(delivery.payload.workflowInstanceId),
|
|
43
|
+
activationId: activationId(delivery.payload.activationId),
|
|
44
|
+
};
|
|
45
|
+
if (!(await this.isAwaitingThisDelivery(command, delivery.payload.intentEventId)))
|
|
46
|
+
return;
|
|
47
|
+
seen.add(delivery.eventId);
|
|
48
|
+
await this.orchestration.acceptOutcome({ ...command, outcome }, {
|
|
49
|
+
commandId: delivery.eventId,
|
|
50
|
+
correlationId: event.correlationId,
|
|
51
|
+
actor: { kind: EventActorKind.System, id: 'delivery-outcome-reactor' },
|
|
52
|
+
occurredAt: event.recordedAt,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
61
55
|
/**
|
|
62
56
|
* A delivery's own completion may only resolve the activation that
|
|
63
57
|
* actually asked to wait on it (an activity outcome of `waiting` with
|