@opensoftware/foreman 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,53 @@
1
+ // The Temporal workflow of a run (ADR 0004, ADR 0067). It runs in Temporal's sandbox, so it only asks the local
2
+ // activity `next` for each step, waits, and hands each fact to `apply`; the logic is in the domain.
3
+ // Stryker disable all: this file runs in Temporal's workflow sandbox, a V8 context of its own that Stryker's mutant
4
+ // switch and coverage never reach; every mutant here would count as not run (ADR 0067).
5
+ import { ActivityCancellationType, CancellationScope, condition, defineQuery, defineSignal, isCancellation, proxyActivities, proxyLocalActivities, setHandler, } from "@temporalio/workflow";
6
+ export const viewQuery = defineQuery("view");
7
+ export const steeringQuery = defineQuery("steering");
8
+ export const steerSignal = defineSignal("steer");
9
+ export const gateSignal = defineSignal("gate");
10
+ const local = proxyLocalActivities({ startToCloseTimeout: "1 minute" });
11
+ const remote = proxyActivities({
12
+ startToCloseTimeout: "1 day",
13
+ heartbeatTimeout: "1 minute",
14
+ retry: { maximumAttempts: 3 },
15
+ cancellationType: ActivityCancellationType.WAIT_CANCELLATION_COMPLETED,
16
+ });
17
+ export async function factoryRun({ view, definition }) {
18
+ let run = view;
19
+ const steering = [];
20
+ const decisions = [];
21
+ setHandler(viewQuery, () => run);
22
+ setHandler(steeringQuery, () => steering);
23
+ setHandler(steerSignal, (message) => void steering.push(message));
24
+ setHandler(gateSignal, (decision) => void decisions.push(decision));
25
+ const settle = async (fact) => {
26
+ run = await CancellationScope.nonCancellable(() => local.apply(run, fact));
27
+ };
28
+ try {
29
+ await remote.publishStarted(run);
30
+ for (let step = await local.next(run, definition); step.kind !== "end"; step = await local.next(run, definition)) {
31
+ const { index } = step;
32
+ if (step.kind === "request-gate") {
33
+ run = await local.apply(run, await remote.requestGate(run, definition, index));
34
+ }
35
+ else if (step.kind === "await-gate") {
36
+ const { gateId } = step;
37
+ await condition(() => decisions.some((decision) => decision.gateId === gateId));
38
+ const decision = decisions.find((candidate) => candidate.gateId === gateId);
39
+ run = await local.apply(run, { kind: "gate", index, ...decision });
40
+ }
41
+ else {
42
+ run = await local.apply(run, { kind: "stage-started", index });
43
+ await settle(await remote.runStage(run, definition, index, steering.length));
44
+ }
45
+ }
46
+ }
47
+ catch (error) {
48
+ await settle(isCancellation(error) ? { kind: "cancelled" } : { kind: "error", message: String(error) });
49
+ }
50
+ await CancellationScope.nonCancellable(() => remote.publishCompleted(run));
51
+ return run;
52
+ }
53
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/workflows/run.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,oGAAoG;AACpG,oHAAoH;AACpH,wFAAwF;AACxF,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAI9B,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAU,MAAM,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAW,UAAU,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAW,OAAO,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAiB,MAAM,CAAC,CAAC;AAE/D,MAAM,KAAK,GAAG,oBAAoB,CAAa,EAAE,mBAAmB,EAAE,UAAU,EAAE,CAAC,CAAC;AACpF,MAAM,MAAM,GAAG,eAAe,CAAa;IACzC,mBAAmB,EAAE,OAAO;IAC5B,gBAAgB,EAAE,UAAU;IAC5B,KAAK,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE;IAC7B,gBAAgB,EAAE,wBAAwB,CAAC,2BAA2B;CACvE,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,E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