@atolis-hq/wake 0.3.13 → 0.3.14
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.
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { selectRunExecutionEvent } from '../../execution/index.js';
|
|
2
2
|
import { correlationId, EventActorKind, } from '../../kernel/index.js';
|
|
3
3
|
import { selectOrchestrationEvent } from '../contracts/event-decoder.js';
|
|
4
|
+
import { OrchestrationEventType, } from '../contracts/events.js';
|
|
4
5
|
import { workflowInstanceId, workflowName, } from '../contracts/identifiers.js';
|
|
6
|
+
import { isWorkflowInstanceStream } from '../contracts/streams.js';
|
|
5
7
|
const checkpoint = 'reactor:orchestration.watch';
|
|
6
8
|
export function createWatchReactor(orchestration, journal, checkpoints, runs) {
|
|
7
9
|
return {
|
|
8
10
|
async react(event, context) {
|
|
9
11
|
const causalCycle = orchestrationCausalCycleId(selectOrchestrationEvent(event));
|
|
10
|
-
const sourceWorkflowInstanceId = await
|
|
12
|
+
const sourceWorkflowInstanceId = await resolveTriggerWorkflowInstanceId(event, runs);
|
|
11
13
|
for (const match of await orchestration.listWatchMatches(event, context)) {
|
|
12
14
|
if (sourceWorkflowInstanceId !== undefined &&
|
|
13
15
|
match.parent.workflowInstanceId !== sourceWorkflowInstanceId)
|
|
@@ -58,11 +60,24 @@ function commandContext(event) {
|
|
|
58
60
|
/**
|
|
59
61
|
* A run-lifecycle event (e.g. `execution.run-succeeded`) fires for every run
|
|
60
62
|
* in the system, including a watch's own spawned child re-running its own
|
|
61
|
-
* activity on retry. Without
|
|
63
|
+
* activity on retry. Without scoping, `listWatchMatches` would treat any
|
|
62
64
|
* currently-eligible parent's declared event type as a match regardless of
|
|
63
65
|
* which run actually produced it, causing a child's own retry (or an
|
|
64
66
|
* unrelated workflow's run) to spuriously re-trigger the same watch.
|
|
67
|
+
*
|
|
68
|
+
* For orchestration events, only `SignalWaitStarted` is scoped to its
|
|
69
|
+
* stream's instance; this is currently the only orchestration event type
|
|
70
|
+
* known to benefit from stream-based filtering. Other orchestration events
|
|
71
|
+
* like `ChildCompleted` are cross-instance coordination facts by design and
|
|
72
|
+
* must fall through unchanged to the async resolver to preserve their
|
|
73
|
+
* existing multi-instance coordination paths.
|
|
65
74
|
*/
|
|
75
|
+
async function resolveTriggerWorkflowInstanceId(event, runs) {
|
|
76
|
+
if (event.eventType === OrchestrationEventType.SignalWaitStarted &&
|
|
77
|
+
isWorkflowInstanceStream(event.stream))
|
|
78
|
+
return event.stream.id;
|
|
79
|
+
return resolveRunWorkflowInstanceId(event, runs);
|
|
80
|
+
}
|
|
66
81
|
async function resolveRunWorkflowInstanceId(event, runs) {
|
|
67
82
|
if (runs === undefined)
|
|
68
83
|
return undefined;
|