@atolis-hq/wake 0.3.53 → 0.3.54
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,4 +1,4 @@
|
|
|
1
|
-
import { RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
1
|
+
import { ActivationClaimConflictError, RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
2
2
|
import { correlationId, EventActorKind, } from '../../kernel/index.js';
|
|
3
3
|
import { WorkflowStatus } from '../../orchestration/index.js';
|
|
4
4
|
import { WorkStatus } from '../../work/index.js';
|
|
@@ -141,15 +141,23 @@ export function createAdvanceOnce(orchestration, execution, resources, clock, de
|
|
|
141
141
|
const correlated = await resources.correlationsForWork(selected.workflow.workItemId);
|
|
142
142
|
const resourceViews = (await Promise.all(correlated.map((entry) => resources.get(entry.resourceId)))).filter((resource) => resource !== null);
|
|
143
143
|
const ineligible = await runnerIneligibility();
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
let run;
|
|
145
|
+
try {
|
|
146
|
+
run = await execution.attempt(selected.activation, {
|
|
147
|
+
workItemId: selected.workflow.workItemId,
|
|
148
|
+
workflowInstanceId: selected.workflow.workflowInstanceId,
|
|
149
|
+
orchestrationGroupId: selected.workflow.orchestrationGroupId,
|
|
150
|
+
resources: resourceViews,
|
|
151
|
+
sessionPolicy: selected.workflow.parentWorkflowInstanceId === undefined ? 'resume-stage' : 'fresh',
|
|
152
|
+
awaitImmediateCompletion: true,
|
|
153
|
+
...(ineligible.size === 0 ? {} : { ineligibleRunners: ineligible }),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error instanceof ActivationClaimConflictError)
|
|
158
|
+
return { kind: 'no-work' };
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
153
161
|
if (run.status === RunStatus.Succeeded && run.outcome !== undefined) {
|
|
154
162
|
if (await isDispatchPaused())
|
|
155
163
|
return { kind: 'paused' };
|
|
@@ -2,13 +2,19 @@ import { EventActorKind, EventSourceKind, } from '../../kernel/index.js';
|
|
|
2
2
|
import { createActivationExecutionEventDraft } from '../contracts/event-factory.js';
|
|
3
3
|
import { decodeActivationExecutionEvent, ExecutionEventType, } from '../contracts/events.js';
|
|
4
4
|
import { activationStream } from '../contracts/streams.js';
|
|
5
|
+
export class ActivationClaimConflictError extends Error {
|
|
6
|
+
constructor(activationId) {
|
|
7
|
+
super(`Activation ${activationId} already has an active Run claim`);
|
|
8
|
+
this.name = 'ActivationClaimConflictError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
5
11
|
export async function claimActivation(input) {
|
|
6
12
|
const { journal, clock, config, activationId, runId, owner, occurredAt } = input;
|
|
7
13
|
const stream = activationStream(activationId);
|
|
8
14
|
const events = (await journal.readStream(stream)).map(decodeActivationExecutionEvent);
|
|
9
15
|
const last = events.at(-1);
|
|
10
16
|
if (last?.eventType === ExecutionEventType.ActivationClaimed && claimIsUnexpired(last, clock))
|
|
11
|
-
throw new
|
|
17
|
+
throw new ActivationClaimConflictError(activationId);
|
|
12
18
|
await journal.append(stream, events.length, [
|
|
13
19
|
createActivationExecutionEventDraft({
|
|
14
20
|
eventId: `${activationId}:claim:${runId}`,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './application/execution-projection.js';
|
|
2
2
|
export * from './application/execution-service.js';
|
|
3
|
+
export * from './application/activation-claim.js';
|
|
3
4
|
export * from './application/recovery-service.js';
|
|
4
5
|
export * from './application/run-repository.js';
|
|
5
6
|
export * from './contracts/commands.js';
|