@atolis-hq/wake 0.4.61 → 0.4.63
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.
- package/dist/src/bootstrap/composition-root.d.ts +4 -1
- package/dist/src/bootstrap/composition-root.js +5 -2
- package/dist/src/bootstrap/config/root-schema.d.ts +2 -2
- package/dist/src/bootstrap/integration-runtime.d.ts +4 -2
- package/dist/src/bootstrap/integration-runtime.js +74 -13
- package/dist/src/bootstrap/surface-api-applications.js +2 -0
- package/dist/src/bootstrap/surface-api-trigger-applications.d.ts +3 -0
- package/dist/src/bootstrap/surface-api-trigger-applications.js +79 -0
- package/dist/src/bootstrap/surface-api-work-applications.js +8 -0
- package/dist/src/bootstrap/trigger-checkpoint-store.d.ts +5 -5
- package/dist/src/bootstrap/trigger-checkpoint-store.js +15 -40
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/control-plane-projection.js +11 -1
- package/dist/src/control-plane/application/runner-pipeline.js +0 -2
- package/dist/src/control-plane/application/trigger-diagnostics.d.ts +33 -0
- package/dist/src/control-plane/application/trigger-diagnostics.js +38 -0
- package/dist/src/control-plane/application/trigger-facts.d.ts +11 -0
- package/dist/src/control-plane/application/trigger-facts.js +38 -0
- package/dist/src/control-plane/application/trigger-invocation-projection.d.ts +4 -0
- package/dist/src/control-plane/application/trigger-invocation-projection.js +32 -0
- package/dist/src/control-plane/application/trigger-projection.d.ts +24 -0
- package/dist/src/control-plane/application/trigger-projection.js +98 -0
- package/dist/src/control-plane/application/trigger-reactor.d.ts +4 -0
- package/dist/src/control-plane/application/trigger-reactor.js +30 -0
- package/dist/src/control-plane/application/trigger-recovery.d.ts +10 -0
- package/dist/src/control-plane/application/trigger-recovery.js +61 -0
- package/dist/src/control-plane/application/trigger-rules.d.ts +19 -0
- package/dist/src/control-plane/application/trigger-rules.js +38 -0
- package/dist/src/control-plane/application/trigger-service-ports.d.ts +21 -0
- package/dist/src/control-plane/application/trigger-service-ports.js +1 -0
- package/dist/src/control-plane/application/trigger-service.d.ts +29 -27
- package/dist/src/control-plane/application/trigger-service.js +188 -101
- package/dist/src/control-plane/application/trigger-source-cursor.d.ts +16 -0
- package/dist/src/control-plane/application/trigger-source-cursor.js +35 -0
- package/dist/src/control-plane/application/trigger-state-reader.d.ts +13 -0
- package/dist/src/control-plane/application/trigger-state-reader.js +34 -0
- package/dist/src/control-plane/application/trigger-workflow.d.ts +17 -0
- package/dist/src/control-plane/application/trigger-workflow.js +18 -0
- package/dist/src/control-plane/contracts/event-factory.js +10 -0
- package/dist/src/control-plane/contracts/events.d.ts +50 -3
- package/dist/src/control-plane/contracts/events.js +100 -4
- package/dist/src/control-plane/contracts/streams.d.ts +9 -2
- package/dist/src/control-plane/contracts/streams.js +13 -1
- package/dist/src/control-plane/contracts/trigger-diagnostics.d.ts +53 -0
- package/dist/src/control-plane/contracts/trigger-diagnostics.js +23 -0
- package/dist/src/control-plane/domain/cron-trigger-policy.d.ts +2 -1
- package/dist/src/control-plane/domain/cron-trigger-policy.js +14 -1
- package/dist/src/control-plane/index.d.ts +4 -0
- package/dist/src/control-plane/index.js +4 -0
- package/dist/src/orchestration/contracts/config.d.ts +2 -2
- package/dist/src/surfaces/api/contracts/index.d.ts +1 -0
- package/dist/src/surfaces/api/contracts/index.js +1 -0
- package/dist/src/surfaces/api/contracts/transport-values.d.ts +8 -0
- package/dist/src/surfaces/api/contracts/transport-values.js +23 -0
- package/dist/src/surfaces/api/contracts/triggers.d.ts +22 -0
- package/dist/src/surfaces/api/contracts/triggers.js +8 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +1 -0
- package/dist/src/surfaces/api/contracts/workflow-diagram.d.ts +4 -4
- package/dist/src/surfaces/api/routes/applications.d.ts +7 -1
- package/dist/src/surfaces/api/routes/commands.js +10 -0
- package/dist/src/surfaces/api/routes/read.js +16 -0
- package/dist/src/surfaces/web-assets/assets/index-9IfrHvBo.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-CCvwzTeC.js +0 -1131
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ControlEventType, selectControlEvent } from '../contracts/events.js';
|
|
2
|
+
import { ControlStreamKind } from '../contracts/streams.js';
|
|
3
|
+
/** One history document per top-level WorkItem, independent of operational scope state. */
|
|
4
|
+
export const triggerInvocationProjection = {
|
|
5
|
+
name: ControlStreamKind.TriggerInvocation,
|
|
6
|
+
select(envelope) {
|
|
7
|
+
const event = selectControlEvent(envelope);
|
|
8
|
+
return event?.stream.kind === ControlStreamKind.TriggerInvocation
|
|
9
|
+
? { key: event.stream.id }
|
|
10
|
+
: null;
|
|
11
|
+
},
|
|
12
|
+
initial: () => null,
|
|
13
|
+
project(previous, envelope) {
|
|
14
|
+
const event = selectControlEvent(envelope);
|
|
15
|
+
if (event === null)
|
|
16
|
+
return previous;
|
|
17
|
+
switch (event.event.eventType) {
|
|
18
|
+
case ControlEventType.TriggerInvocationClaimed:
|
|
19
|
+
return { claim: event.event.payload, claimedAt: event.event.occurredAt };
|
|
20
|
+
case ControlEventType.TriggerInvocationStarted:
|
|
21
|
+
if (previous === null)
|
|
22
|
+
throw new Error('Trigger start without invocation claim');
|
|
23
|
+
return { ...previous, startedAt: event.event.occurredAt };
|
|
24
|
+
case ControlEventType.TriggerInvocationFinished:
|
|
25
|
+
if (previous === null)
|
|
26
|
+
throw new Error('Trigger result without invocation claim');
|
|
27
|
+
return { ...previous, result: event.event.payload, finishedAt: event.event.occurredAt };
|
|
28
|
+
default:
|
|
29
|
+
return previous;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProjectionDefinition } from '@atolis-hq/eventing';
|
|
2
|
+
import { ControlEventType, type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
|
|
3
|
+
export declare const triggerProjectionName = "control-plane-triggers";
|
|
4
|
+
export declare const maximumTriggerSources = 64;
|
|
5
|
+
export interface TriggerInvocationView {
|
|
6
|
+
readonly claim: ControlEventPayloads[typeof ControlEventType.TriggerInvocationClaimed];
|
|
7
|
+
readonly claimedAt: string;
|
|
8
|
+
readonly startedAt?: string;
|
|
9
|
+
readonly result?: ControlEventPayloads[typeof ControlEventType.TriggerInvocationFinished];
|
|
10
|
+
readonly finishedAt?: string;
|
|
11
|
+
readonly failureOutcomeCount?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface TriggerView {
|
|
14
|
+
readonly lastStarts: Readonly<Record<string, string>>;
|
|
15
|
+
readonly pauses: Readonly<Record<string, string>>;
|
|
16
|
+
/** Latest recorded request per trigger, rather than an occurrence history. */
|
|
17
|
+
readonly requests: readonly ControlEventPayloads[typeof ControlEventType.TriggerRequestRecorded][];
|
|
18
|
+
readonly coalesced: Readonly<Record<string, ControlEventPayloads[typeof ControlEventType.TriggerRequestRecorded] & {
|
|
19
|
+
readonly sources: readonly TriggerSource[];
|
|
20
|
+
}>>;
|
|
21
|
+
/** Operational projections contain only active claims; explicit service inspection includes history. */
|
|
22
|
+
readonly invocations: readonly TriggerInvocationView[];
|
|
23
|
+
}
|
|
24
|
+
export declare const triggerProjection: ProjectionDefinition<TriggerView>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ControlEventType, TriggerRequestDisposition, selectControlEvent, } from '../contracts/events.js';
|
|
2
|
+
export const triggerProjectionName = 'control-plane-triggers';
|
|
3
|
+
export const maximumTriggerSources = 64;
|
|
4
|
+
export const triggerProjection = {
|
|
5
|
+
name: triggerProjectionName,
|
|
6
|
+
select(envelope) {
|
|
7
|
+
const event = selectControlEvent(envelope);
|
|
8
|
+
return event !== null && 'coordinationKey' in event.event.payload
|
|
9
|
+
? { key: event.event.payload.coordinationKey }
|
|
10
|
+
: null;
|
|
11
|
+
},
|
|
12
|
+
initial: () => ({ lastStarts: {}, pauses: {}, requests: [], coalesced: {}, invocations: [] }),
|
|
13
|
+
project(previous, envelope) {
|
|
14
|
+
const event = selectControlEvent(envelope);
|
|
15
|
+
if (event === null)
|
|
16
|
+
return previous;
|
|
17
|
+
switch (event.event.eventType) {
|
|
18
|
+
case ControlEventType.TriggerRequestRecorded: {
|
|
19
|
+
const request = event.event.payload;
|
|
20
|
+
return {
|
|
21
|
+
...previous,
|
|
22
|
+
requests: [
|
|
23
|
+
...previous.requests.filter((last) => last.triggerId !== request.triggerId),
|
|
24
|
+
request,
|
|
25
|
+
],
|
|
26
|
+
coalesced: request.disposition === TriggerRequestDisposition.Coalesced
|
|
27
|
+
? {
|
|
28
|
+
...previous.coalesced,
|
|
29
|
+
[request.coordinationKey]: {
|
|
30
|
+
...request,
|
|
31
|
+
sources: [
|
|
32
|
+
...(previous.coalesced[request.coordinationKey]?.sources ?? []),
|
|
33
|
+
request.source,
|
|
34
|
+
].slice(0, maximumTriggerSources),
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
: withoutCoalesced(previous.coalesced, request),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
case ControlEventType.TriggerInvocationClaimed: {
|
|
41
|
+
const claim = event.event.payload;
|
|
42
|
+
const { [claim.coordinationKey]: _, ...coalesced } = previous.coalesced;
|
|
43
|
+
return {
|
|
44
|
+
...previous,
|
|
45
|
+
coalesced,
|
|
46
|
+
invocations: [...previous.invocations, { claim, claimedAt: event.event.occurredAt }],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
case ControlEventType.TriggerInvocationStarted: {
|
|
50
|
+
const payload = event.event.payload;
|
|
51
|
+
return {
|
|
52
|
+
...previous,
|
|
53
|
+
lastStarts: { ...previous.lastStarts, [payload.triggerId]: event.event.occurredAt },
|
|
54
|
+
invocations: previous.invocations.map((invocation) => invocation.claim.workflowInstanceId === payload.workflowInstanceId
|
|
55
|
+
? { ...invocation, startedAt: event.event.occurredAt }
|
|
56
|
+
: invocation),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
case ControlEventType.TriggerInvocationFinished: {
|
|
60
|
+
const payload = event.event.payload;
|
|
61
|
+
return {
|
|
62
|
+
...previous,
|
|
63
|
+
invocations: previous.invocations.filter((invocation) => invocation.claim.workflowInstanceId !== payload.workflowInstanceId),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
case ControlEventType.TriggerPaused: {
|
|
67
|
+
const payload = event.event.payload;
|
|
68
|
+
return {
|
|
69
|
+
...previous,
|
|
70
|
+
pauses: { ...previous.pauses, [payload.triggerId]: payload.reason },
|
|
71
|
+
invocations: pausedInvocations(previous, payload),
|
|
72
|
+
coalesced: Object.fromEntries(Object.entries(previous.coalesced).filter(([key]) => key !== payload.coordinationKey)),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
case ControlEventType.TriggerResumed: {
|
|
76
|
+
const { [event.event.payload.triggerId]: _, ...pauses } = previous.pauses;
|
|
77
|
+
return { ...previous, pauses };
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
return previous;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
function withoutCoalesced(coalesced, request) {
|
|
85
|
+
const key = request.coordinationKey;
|
|
86
|
+
// An ineligible new occurrence does not discard another trigger's coalesced request.
|
|
87
|
+
if (coalesced[key]?.triggerId !== request.triggerId ||
|
|
88
|
+
JSON.stringify(coalesced[key]?.source) !== JSON.stringify(request.source))
|
|
89
|
+
return coalesced;
|
|
90
|
+
const { [key]: _, ...rest } = coalesced;
|
|
91
|
+
return rest;
|
|
92
|
+
}
|
|
93
|
+
function pausedInvocations(previous, payload) {
|
|
94
|
+
return previous.invocations.map((invocation) => payload.workflowInstanceId === invocation.claim.workflowInstanceId &&
|
|
95
|
+
payload.outcomeCount !== undefined
|
|
96
|
+
? { ...invocation, failureOutcomeCount: payload.outcomeCount }
|
|
97
|
+
: invocation);
|
|
98
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type EventEnvelope } from '@atolis-hq/eventing';
|
|
2
|
+
import type { TriggerConfig } from '../contracts/config.js';
|
|
3
|
+
import type { TriggerService } from './trigger-service.js';
|
|
4
|
+
export declare function createTriggerReactor(service: TriggerService, config: TriggerConfig, decode: (event: EventEnvelope) => void): import("@atolis-hq/eventing").EventProcessor;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { correlationId, defineEventProcessor, EventActorKind, EventProcessorCategory, EventProcessorReplayPolicy, } from '@atolis-hq/eventing';
|
|
2
|
+
import { TriggerSourceKind } from '../contracts/events.js';
|
|
3
|
+
import { ControlStreamKind } from '../contracts/streams.js';
|
|
4
|
+
export function createTriggerReactor(service, config, decode) {
|
|
5
|
+
return defineEventProcessor({
|
|
6
|
+
consumer: `reactor:control-plane.trigger:${config.id}`,
|
|
7
|
+
name: 'workflow-triggers',
|
|
8
|
+
owner: ControlStreamKind.Global,
|
|
9
|
+
category: EventProcessorCategory.Reactor,
|
|
10
|
+
replayPolicy: EventProcessorReplayPolicy.Idempotent,
|
|
11
|
+
select(event) {
|
|
12
|
+
if (!config.on.events?.includes(event.event.eventType))
|
|
13
|
+
return null;
|
|
14
|
+
decode(event);
|
|
15
|
+
return event;
|
|
16
|
+
},
|
|
17
|
+
async handle(event) {
|
|
18
|
+
await service.start(config, {
|
|
19
|
+
kind: TriggerSourceKind.Event,
|
|
20
|
+
eventId: event.event.eventId,
|
|
21
|
+
eventType: event.event.eventType,
|
|
22
|
+
}, {
|
|
23
|
+
commandId: `trigger:${config.id}:${event.event.eventId}`,
|
|
24
|
+
correlationId: correlationId(`trigger:${config.id}:${event.event.eventId}`),
|
|
25
|
+
occurredAt: event.event.occurredAt,
|
|
26
|
+
actor: { kind: EventActorKind.System, id: config.id },
|
|
27
|
+
}, event);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CommandContext } from '@atolis-hq/eventing';
|
|
2
|
+
import type { TriggerFactInput } from './trigger-facts.js';
|
|
3
|
+
import type { TriggerInvocationView } from './trigger-projection.js';
|
|
4
|
+
import { type TriggerWorkflowPorts } from './trigger-workflow.js';
|
|
5
|
+
interface TriggerRecoveryPorts extends TriggerWorkflowPorts {
|
|
6
|
+
readonly emit: (input: TriggerFactInput, context: CommandContext, eventId: string) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Blocked invocations remain recoverable through operator retry or clarification. */
|
|
9
|
+
export declare function recoverTriggerInvocation(dependencies: TriggerRecoveryPorts, invocation: TriggerInvocationView, context: CommandContext): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { correlationId, EventActorKind } from '@atolis-hq/eventing';
|
|
2
|
+
import { workflowInstanceId } from '../../orchestration/index.js';
|
|
3
|
+
import { workItemId } from '../../work/index.js';
|
|
4
|
+
import { ControlEventType } from '../contracts/events.js';
|
|
5
|
+
import { exhaustedFailures, finishedStatus } from './trigger-rules.js';
|
|
6
|
+
import { ensureTriggerWorkflow } from './trigger-workflow.js';
|
|
7
|
+
/** Blocked invocations remain recoverable through operator retry or clarification. */
|
|
8
|
+
export async function recoverTriggerInvocation(dependencies, invocation, context) {
|
|
9
|
+
const claim = invocation.claim;
|
|
10
|
+
const workflow = workflowInstanceId(claim.workflowInstanceId);
|
|
11
|
+
const invocationContext = {
|
|
12
|
+
commandId: `${workflow}:create`,
|
|
13
|
+
correlationId: correlationId(workflow),
|
|
14
|
+
occurredAt: invocation.claimedAt,
|
|
15
|
+
actor: { kind: EventActorKind.System, id: claim.triggerId },
|
|
16
|
+
};
|
|
17
|
+
const instance = await ensureTriggerWorkflow(dependencies, claim, invocationContext);
|
|
18
|
+
if (invocation.startedAt === undefined) {
|
|
19
|
+
await dependencies.emit({
|
|
20
|
+
eventType: ControlEventType.TriggerInvocationStarted,
|
|
21
|
+
payload: {
|
|
22
|
+
triggerId: claim.triggerId,
|
|
23
|
+
coordinationKey: claim.coordinationKey,
|
|
24
|
+
source: claim.source,
|
|
25
|
+
workItemId: workItemId(claim.workItemId),
|
|
26
|
+
workflowInstanceId: workflow,
|
|
27
|
+
workflowName: claim.workflowName,
|
|
28
|
+
},
|
|
29
|
+
}, invocationContext, `${workflow}:${ControlEventType.TriggerInvocationStarted}`);
|
|
30
|
+
}
|
|
31
|
+
if (instance === null)
|
|
32
|
+
return;
|
|
33
|
+
if (exhaustedFailures(instance) &&
|
|
34
|
+
invocation.failureOutcomeCount !== instance.acceptedOutcomes.length) {
|
|
35
|
+
// Retrying remains an explicit workflow command; an operator must resume the trigger.
|
|
36
|
+
await dependencies.emit({
|
|
37
|
+
eventType: ControlEventType.TriggerPaused,
|
|
38
|
+
payload: {
|
|
39
|
+
triggerId: claim.triggerId,
|
|
40
|
+
coordinationKey: claim.coordinationKey,
|
|
41
|
+
workflowInstanceId: claim.workflowInstanceId,
|
|
42
|
+
outcomeCount: instance.acceptedOutcomes.length,
|
|
43
|
+
reason: instance.blockReason ?? 'Invocation exhausted automatic failure retries',
|
|
44
|
+
},
|
|
45
|
+
}, context, `${workflow}:pause:${instance.acceptedOutcomes.length}`);
|
|
46
|
+
}
|
|
47
|
+
const status = finishedStatus(instance);
|
|
48
|
+
if (status === undefined)
|
|
49
|
+
return;
|
|
50
|
+
await dependencies.emit({
|
|
51
|
+
eventType: ControlEventType.TriggerInvocationFinished,
|
|
52
|
+
payload: {
|
|
53
|
+
triggerId: claim.triggerId,
|
|
54
|
+
coordinationKey: claim.coordinationKey,
|
|
55
|
+
workItemId: claim.workItemId,
|
|
56
|
+
workflowInstanceId: workflow,
|
|
57
|
+
status,
|
|
58
|
+
...(instance.blockReason === undefined ? {} : { reason: instance.blockReason }),
|
|
59
|
+
},
|
|
60
|
+
}, context, `${workflow}:finished`);
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EventEnvelope } from '@atolis-hq/eventing';
|
|
2
|
+
import { type WorkflowInstanceView } from '../../orchestration/index.js';
|
|
3
|
+
import { type ControlEventPayloads, type ControlEventType } from '../contracts/events.js';
|
|
4
|
+
import type { TriggerView } from './trigger-projection.js';
|
|
5
|
+
type FinishedStatus = ControlEventPayloads[typeof ControlEventType.TriggerInvocationFinished]['status'];
|
|
6
|
+
export declare function hasActiveInvocation(view: TriggerView, coordinationKey: string): boolean;
|
|
7
|
+
/** Events caused by this scope's own invocations must not re-trigger it. */
|
|
8
|
+
export declare function isOwnScopeSource(view: TriggerView, scope: {
|
|
9
|
+
readonly triggerId: string;
|
|
10
|
+
readonly coordinationKey: string;
|
|
11
|
+
}, event: EventEnvelope | undefined, resolve: {
|
|
12
|
+
readonly keyOf: (triggerId: string) => string | undefined;
|
|
13
|
+
readonly sourceWorkItem: (event: EventEnvelope) => Promise<string | null>;
|
|
14
|
+
readonly invocationScope: (workItemId: string) => Promise<string | null>;
|
|
15
|
+
}): Promise<boolean>;
|
|
16
|
+
/** Blocking or a failed outcome with no retry wait left ends automatic workflow progress. */
|
|
17
|
+
export declare function exhaustedFailures(instance: WorkflowInstanceView): boolean;
|
|
18
|
+
export declare function finishedStatus(instance: WorkflowInstanceView): FinishedStatus | undefined;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
2
|
+
import { WorkflowStatus } from '../../orchestration/index.js';
|
|
3
|
+
import { selectControlEvent, } from '../contracts/events.js';
|
|
4
|
+
export function hasActiveInvocation(view, coordinationKey) {
|
|
5
|
+
return view.invocations.some((invocation) => invocation.claim.coordinationKey === coordinationKey && invocation.result === undefined);
|
|
6
|
+
}
|
|
7
|
+
/** Events caused by this scope's own invocations must not re-trigger it. */
|
|
8
|
+
export async function isOwnScopeSource(view, scope, event, resolve) {
|
|
9
|
+
if (event === undefined)
|
|
10
|
+
return false;
|
|
11
|
+
const control = selectControlEvent(event);
|
|
12
|
+
if (control !== null && 'triggerId' in control.event.payload) {
|
|
13
|
+
const id = control.event.payload.triggerId;
|
|
14
|
+
if (id === scope.triggerId ||
|
|
15
|
+
('coordinationKey' in control.event.payload &&
|
|
16
|
+
control.event.payload.coordinationKey === scope.coordinationKey) ||
|
|
17
|
+
resolve.keyOf(id) === scope.coordinationKey ||
|
|
18
|
+
view.invocations.some((invocation) => invocation.claim.triggerId === id &&
|
|
19
|
+
invocation.claim.coordinationKey === scope.coordinationKey))
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const sourceItem = await resolve.sourceWorkItem(event);
|
|
23
|
+
return (sourceItem !== null && (await resolve.invocationScope(sourceItem)) === scope.coordinationKey);
|
|
24
|
+
}
|
|
25
|
+
/** Blocking or a failed outcome with no retry wait left ends automatic workflow progress. */
|
|
26
|
+
export function exhaustedFailures(instance) {
|
|
27
|
+
const failed = instance.lastOutcome?.kind === ActivityOutcomeKind.Failed;
|
|
28
|
+
return (instance.status === WorkflowStatus.Blocked ||
|
|
29
|
+
(failed && instance.status === WorkflowStatus.Completed) ||
|
|
30
|
+
(failed &&
|
|
31
|
+
instance.status === WorkflowStatus.Waiting &&
|
|
32
|
+
instance.waitingFor?.signalKind === ActivityOutcomeKind.Failed));
|
|
33
|
+
}
|
|
34
|
+
export function finishedStatus(instance) {
|
|
35
|
+
if (instance.status === WorkflowStatus.Completed || instance.status === WorkflowStatus.Superseded)
|
|
36
|
+
return instance.status;
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EventEnvelope, EventJournal, ProcessorRunSerialiser, ProcessorStateStore } from '@atolis-hq/eventing';
|
|
2
|
+
import type { IdGenerator } from '../../kernel/index.js';
|
|
3
|
+
import type { TriggerConfig } from '../contracts/config.js';
|
|
4
|
+
import type { TriggerInvocationView } from './trigger-projection.js';
|
|
5
|
+
import type { TriggerCheckpointStore } from './trigger-source-cursor.js';
|
|
6
|
+
import type { TriggerWorkflowPorts } from './trigger-workflow.js';
|
|
7
|
+
export interface TriggerServiceDependencies extends TriggerWorkflowPorts {
|
|
8
|
+
readonly checkpoint: TriggerCheckpointStore;
|
|
9
|
+
readonly journal: EventJournal;
|
|
10
|
+
readonly state: ProcessorStateStore;
|
|
11
|
+
readonly history: () => Promise<readonly TriggerInvocationView[]>;
|
|
12
|
+
readonly invocationScope: (workItemId: string) => Promise<string | null>;
|
|
13
|
+
readonly serialise: ProcessorRunSerialiser;
|
|
14
|
+
readonly ids: IdGenerator;
|
|
15
|
+
readonly configurations: () => readonly TriggerConfig[];
|
|
16
|
+
readonly coordinationKey?: (config: TriggerConfig) => string;
|
|
17
|
+
readonly sourceWorkItem: (event: EventEnvelope) => Promise<string | null>;
|
|
18
|
+
readonly isDispatchPaused: () => Promise<boolean>;
|
|
19
|
+
readonly capacityAvailable: (config: TriggerConfig) => Promise<boolean>;
|
|
20
|
+
readonly now: () => string;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { IdGenerator } from '../../kernel/index.js';
|
|
3
|
-
import { workflowInstanceId, type StartWorkflowInstance } from '../../orchestration/index.js';
|
|
4
|
-
import { workItemId, type CreateWorkItem } from '../../work/index.js';
|
|
1
|
+
import type { CommandContext, EventEnvelope } from '@atolis-hq/eventing';
|
|
5
2
|
import type { TriggerConfig } from '../contracts/config.js';
|
|
6
3
|
import { type TriggerSource } from '../contracts/events.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
readonly orchestration: {
|
|
19
|
-
start(command: StartWorkflowInstance, context: CommandContext): Promise<unknown>;
|
|
20
|
-
get(id: ReturnType<typeof workflowInstanceId>): Promise<{
|
|
21
|
-
readonly workItemId: ReturnType<typeof workItemId>;
|
|
22
|
-
} | null>;
|
|
23
|
-
};
|
|
24
|
-
readonly capacityAvailable: (config: TriggerConfig) => Promise<boolean>;
|
|
25
|
-
readonly now: () => string;
|
|
26
|
-
}
|
|
4
|
+
import { type TriggerSkipDiagnostic } from '../contracts/trigger-diagnostics.js';
|
|
5
|
+
import { type TriggerView } from './trigger-projection.js';
|
|
6
|
+
import type { TriggerServiceDependencies } from './trigger-service-ports.js';
|
|
7
|
+
export type { TriggerServiceDependencies } from './trigger-service-ports.js';
|
|
8
|
+
export type { TriggerCheckpointStore } from './trigger-source-cursor.js';
|
|
9
|
+
export type TriggerInspectionView = TriggerView & {
|
|
10
|
+
readonly diagnostics: readonly TriggerSkipDiagnostic[];
|
|
11
|
+
};
|
|
12
|
+
export declare const triggerCriticalSectionConsumer = "control-plane:trigger-coordination";
|
|
13
|
+
/** Requests and claims are journal facts; the cron cursor is processor recovery state. */
|
|
27
14
|
export declare class TriggerService {
|
|
28
15
|
private readonly dependencies;
|
|
29
16
|
private readonly policy;
|
|
17
|
+
private readonly reader;
|
|
18
|
+
private readonly sourceCursor;
|
|
19
|
+
private readonly diagnostics;
|
|
30
20
|
constructor(dependencies: TriggerServiceDependencies);
|
|
21
|
+
get(): Promise<TriggerInspectionView>;
|
|
22
|
+
reconcile(context: CommandContext): Promise<void>;
|
|
23
|
+
pause(triggerId: string, reason: string, context: CommandContext): Promise<void>;
|
|
24
|
+
resume(triggerId: string, context: CommandContext): Promise<void>;
|
|
31
25
|
run(config: TriggerConfig, context: CommandContext): Promise<readonly string[]>;
|
|
32
|
-
start(config: TriggerConfig, source: TriggerSource, context: CommandContext): Promise<boolean>;
|
|
33
|
-
private
|
|
26
|
+
start(config: TriggerConfig, source: TriggerSource, context: CommandContext, event?: EventEnvelope): Promise<boolean>;
|
|
27
|
+
private serialise;
|
|
28
|
+
private key;
|
|
29
|
+
private commandKey;
|
|
30
|
+
private view;
|
|
31
|
+
private configured;
|
|
32
|
+
private emit;
|
|
33
|
+
private request;
|
|
34
|
+
private suppressed;
|
|
35
|
+
private advanceCoalesced;
|
|
36
|
+
private recover;
|
|
34
37
|
}
|
|
35
|
-
export declare function createTriggerReactor(service: TriggerService, config: TriggerConfig, decode: (event: EventEnvelope) => void): import("@atolis-hq/eventing").EventProcessor;
|