@hotmeshio/hotmesh 0.13.0 → 0.14.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.
- package/README.md +18 -22
- package/build/modules/enums.d.ts +60 -5
- package/build/modules/enums.js +62 -7
- package/build/modules/errors.d.ts +15 -3
- package/build/modules/errors.js +17 -2
- package/build/package.json +6 -1
- package/build/services/activities/activity/context.d.ts +22 -0
- package/build/services/activities/activity/context.js +76 -0
- package/build/services/activities/activity/index.d.ts +116 -0
- package/build/services/activities/activity/index.js +299 -0
- package/build/services/activities/activity/mapping.d.ts +12 -0
- package/build/services/activities/activity/mapping.js +63 -0
- package/build/services/activities/activity/process.d.ts +28 -0
- package/build/services/activities/activity/process.js +100 -0
- package/build/services/activities/activity/protocol.d.ts +39 -0
- package/build/services/activities/activity/protocol.js +151 -0
- package/build/services/activities/activity/state.d.ts +40 -0
- package/build/services/activities/activity/state.js +143 -0
- package/build/services/activities/activity/transition.d.ts +23 -0
- package/build/services/activities/activity/transition.js +71 -0
- package/build/services/activities/activity/verify.d.ts +22 -0
- package/build/services/activities/activity/verify.js +85 -0
- package/build/services/activities/await.d.ts +1 -4
- package/build/services/activities/await.js +2 -36
- package/build/services/activities/cycle.d.ts +1 -11
- package/build/services/activities/cycle.js +3 -46
- package/build/services/activities/hook.d.ts +2 -11
- package/build/services/activities/hook.js +30 -50
- package/build/services/activities/interrupt.d.ts +2 -4
- package/build/services/activities/interrupt.js +4 -38
- package/build/services/activities/signal.d.ts +1 -11
- package/build/services/activities/signal.js +3 -48
- package/build/services/activities/trigger.d.ts +1 -3
- package/build/services/activities/trigger.js +0 -3
- package/build/services/activities/worker.d.ts +3 -6
- package/build/services/activities/worker.js +4 -40
- package/build/services/connector/factory.d.ts +6 -0
- package/build/services/connector/factory.js +24 -0
- package/build/services/durable/activity.d.ts +1 -1
- package/build/services/durable/activity.js +2 -2
- package/build/services/durable/client.d.ts +24 -29
- package/build/services/durable/client.js +24 -29
- package/build/services/durable/connection.d.ts +13 -7
- package/build/services/durable/connection.js +13 -7
- package/build/services/durable/handle.d.ts +58 -40
- package/build/services/durable/handle.js +60 -40
- package/build/services/durable/index.d.ts +148 -286
- package/build/services/durable/index.js +157 -292
- package/build/services/durable/interceptor.d.ts +43 -33
- package/build/services/durable/interceptor.js +59 -39
- package/build/services/durable/schemas/factory.d.ts +1 -1
- package/build/services/durable/schemas/factory.js +168 -38
- package/build/services/durable/telemetry.d.ts +80 -0
- package/build/services/durable/telemetry.js +137 -0
- package/build/services/durable/worker.d.ts +100 -21
- package/build/services/durable/worker.js +304 -63
- package/build/services/durable/workflow/all.d.ts +1 -1
- package/build/services/durable/workflow/all.js +1 -1
- package/build/services/durable/workflow/cancellationScope.d.ts +104 -0
- package/build/services/durable/workflow/cancellationScope.js +139 -0
- package/build/services/durable/workflow/common.d.ts +5 -4
- package/build/services/durable/workflow/common.js +6 -1
- package/build/services/durable/workflow/{waitFor.d.ts → condition.d.ts} +9 -8
- package/build/services/durable/workflow/{waitFor.js → condition.js} +44 -11
- package/build/services/durable/workflow/continueAsNew.d.ts +65 -0
- package/build/services/durable/workflow/continueAsNew.js +92 -0
- package/build/services/durable/workflow/didRun.d.ts +1 -1
- package/build/services/durable/workflow/didRun.js +3 -3
- package/build/services/durable/workflow/enrich.d.ts +5 -0
- package/build/services/durable/workflow/enrich.js +5 -0
- package/build/services/durable/workflow/entityMethods.d.ts +7 -0
- package/build/services/durable/workflow/entityMethods.js +7 -0
- package/build/services/durable/workflow/execHook.js +3 -3
- package/build/services/durable/workflow/execHookBatch.js +2 -2
- package/build/services/durable/workflow/{execChild.d.ts → executeChild.d.ts} +4 -40
- package/build/services/durable/workflow/{execChild.js → executeChild.js} +36 -45
- package/build/services/durable/workflow/hook.d.ts +1 -1
- package/build/services/durable/workflow/hook.js +4 -3
- package/build/services/durable/workflow/index.d.ts +45 -50
- package/build/services/durable/workflow/index.js +46 -51
- package/build/services/durable/workflow/interruption.d.ts +7 -6
- package/build/services/durable/workflow/interruption.js +11 -7
- package/build/services/durable/workflow/patched.d.ts +72 -0
- package/build/services/durable/workflow/patched.js +110 -0
- package/build/services/durable/workflow/proxyActivities.d.ts +7 -7
- package/build/services/durable/workflow/proxyActivities.js +50 -15
- package/build/services/durable/workflow/searchMethods.d.ts +7 -0
- package/build/services/durable/workflow/searchMethods.js +7 -0
- package/build/services/durable/workflow/signal.d.ts +4 -4
- package/build/services/durable/workflow/signal.js +4 -4
- package/build/services/durable/workflow/{sleepFor.d.ts → sleep.d.ts} +7 -7
- package/build/services/durable/workflow/{sleepFor.js → sleep.js} +39 -10
- package/build/services/durable/workflow/terminate.d.ts +55 -0
- package/build/services/durable/workflow/{interrupt.js → terminate.js} +21 -21
- package/build/services/durable/workflow/trace.js +2 -2
- package/build/services/durable/workflow/uuid4.d.ts +14 -0
- package/build/services/durable/workflow/uuid4.js +39 -0
- package/build/services/durable/workflow/{context.d.ts → workflowInfo.d.ts} +5 -5
- package/build/services/durable/workflow/{context.js → workflowInfo.js} +7 -7
- package/build/services/engine/compiler.d.ts +19 -0
- package/build/services/engine/compiler.js +20 -0
- package/build/services/engine/completion.d.ts +46 -0
- package/build/services/engine/completion.js +145 -0
- package/build/services/engine/dispatch.d.ts +24 -0
- package/build/services/engine/dispatch.js +98 -0
- package/build/services/engine/index.d.ts +49 -81
- package/build/services/engine/index.js +175 -573
- package/build/services/engine/init.d.ts +42 -0
- package/build/services/engine/init.js +74 -0
- package/build/services/engine/pubsub.d.ts +50 -0
- package/build/services/engine/pubsub.js +118 -0
- package/build/services/engine/reporting.d.ts +20 -0
- package/build/services/engine/reporting.js +38 -0
- package/build/services/engine/schema.d.ts +23 -0
- package/build/services/engine/schema.js +62 -0
- package/build/services/engine/signal.d.ts +57 -0
- package/build/services/engine/signal.js +117 -0
- package/build/services/engine/state.d.ts +35 -0
- package/build/services/engine/state.js +61 -0
- package/build/services/engine/version.d.ts +31 -0
- package/build/services/engine/version.js +73 -0
- package/build/services/hotmesh/deployment.d.ts +21 -0
- package/build/services/hotmesh/deployment.js +25 -0
- package/build/services/hotmesh/index.d.ts +141 -532
- package/build/services/hotmesh/index.js +222 -673
- package/build/services/hotmesh/init.d.ts +42 -0
- package/build/services/hotmesh/init.js +93 -0
- package/build/services/hotmesh/jobs.d.ts +67 -0
- package/build/services/hotmesh/jobs.js +99 -0
- package/build/services/hotmesh/pubsub.d.ts +38 -0
- package/build/services/hotmesh/pubsub.js +54 -0
- package/build/services/hotmesh/quorum.d.ts +30 -0
- package/build/services/hotmesh/quorum.js +62 -0
- package/build/services/hotmesh/validation.d.ts +6 -0
- package/build/services/hotmesh/validation.js +28 -0
- package/build/services/quorum/index.js +1 -0
- package/build/services/router/consumption/index.d.ts +11 -5
- package/build/services/router/consumption/index.js +24 -17
- package/build/services/router/error-handling/index.d.ts +2 -2
- package/build/services/router/error-handling/index.js +14 -14
- package/build/services/router/index.d.ts +1 -1
- package/build/services/router/index.js +2 -2
- package/build/services/serializer/index.d.ts +22 -0
- package/build/services/serializer/index.js +39 -1
- package/build/services/store/index.d.ts +1 -0
- package/build/services/store/providers/postgres/exporter-sql.d.ts +2 -2
- package/build/services/store/providers/postgres/exporter-sql.js +4 -4
- package/build/services/store/providers/postgres/kvtables.js +7 -6
- package/build/services/store/providers/postgres/kvtypes/hash/basic.js +67 -52
- package/build/services/store/providers/postgres/kvtypes/hash/jsonb.js +87 -72
- package/build/services/store/providers/postgres/kvtypes/hash/udata.js +106 -79
- package/build/services/store/providers/postgres/kvtypes/hash/utils.d.ts +16 -0
- package/build/services/store/providers/postgres/kvtypes/hash/utils.js +29 -16
- package/build/services/store/providers/postgres/postgres.d.ts +1 -0
- package/build/services/store/providers/postgres/postgres.js +14 -4
- package/build/services/stream/factory.d.ts +3 -1
- package/build/services/stream/factory.js +2 -2
- package/build/services/stream/index.d.ts +1 -0
- package/build/services/stream/providers/nats/nats.d.ts +1 -0
- package/build/services/stream/providers/nats/nats.js +1 -0
- package/build/services/stream/providers/postgres/credentials.d.ts +56 -0
- package/build/services/stream/providers/postgres/credentials.js +129 -0
- package/build/services/stream/providers/postgres/kvtables.js +18 -0
- package/build/services/stream/providers/postgres/messages.js +7 -7
- package/build/services/stream/providers/postgres/notifications.js +16 -2
- package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
- package/build/services/stream/providers/postgres/postgres.js +35 -4
- package/build/services/stream/providers/postgres/procedures.d.ts +21 -0
- package/build/services/stream/providers/postgres/procedures.js +213 -0
- package/build/services/stream/providers/postgres/secured.d.ts +34 -0
- package/build/services/stream/providers/postgres/secured.js +146 -0
- package/build/services/stream/providers/postgres/stats.d.ts +1 -0
- package/build/services/stream/providers/postgres/stats.js +1 -0
- package/build/services/stream/registry.d.ts +1 -1
- package/build/services/stream/registry.js +5 -2
- package/build/services/telemetry/index.d.ts +10 -1
- package/build/services/telemetry/index.js +40 -7
- package/build/services/worker/credentials.d.ts +51 -0
- package/build/services/worker/credentials.js +87 -0
- package/build/services/worker/index.d.ts +2 -2
- package/build/services/worker/index.js +7 -6
- package/build/types/codec.d.ts +84 -0
- package/build/types/codec.js +2 -0
- package/build/types/durable.d.ts +104 -28
- package/build/types/error.d.ts +10 -1
- package/build/types/hotmesh.d.ts +67 -4
- package/build/types/index.d.ts +2 -1
- package/build/types/provider.d.ts +2 -2
- package/build/types/quorum.d.ts +35 -1
- package/build/types/stream.d.ts +12 -6
- package/package.json +6 -1
- package/build/services/activities/activity.d.ts +0 -192
- package/build/services/activities/activity.js +0 -786
- package/build/services/durable/workflow/interrupt.d.ts +0 -55
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { EngineService } from '../../engine';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { StoreService } from '../../store';
|
|
4
|
+
import { TelemetryService } from '../../telemetry';
|
|
5
|
+
import { ActivityData, ActivityLeg, ActivityMetadata, ActivityType } from '../../../types/activity';
|
|
6
|
+
import { ProviderClient, ProviderTransaction, TransactionResultList } from '../../../types/provider';
|
|
7
|
+
import { JobState, JobStatus } from '../../../types/job';
|
|
8
|
+
import { StringAnyType } from '../../../types/serializer';
|
|
9
|
+
import { StreamCode, StreamData, StreamStatus } from '../../../types/stream';
|
|
10
|
+
/**
|
|
11
|
+
* Base class for every node in the workflow DAG.
|
|
12
|
+
*
|
|
13
|
+
* An activity's lifecycle flows top-to-bottom through this file:
|
|
14
|
+
* enter → load state → map data → persist → transition → complete.
|
|
15
|
+
*
|
|
16
|
+
* Each section delegates to a purpose-specific module inside `activity/`.
|
|
17
|
+
* Open the module when you need implementation detail; read this file
|
|
18
|
+
* when you need the big picture.
|
|
19
|
+
*/
|
|
20
|
+
declare class Activity {
|
|
21
|
+
config: ActivityType;
|
|
22
|
+
data: ActivityData;
|
|
23
|
+
hook: ActivityData;
|
|
24
|
+
metadata: ActivityMetadata;
|
|
25
|
+
/** @hidden */
|
|
26
|
+
store: StoreService<ProviderClient, ProviderTransaction>;
|
|
27
|
+
engine: EngineService;
|
|
28
|
+
logger: ILogger;
|
|
29
|
+
context: JobState;
|
|
30
|
+
status: StreamStatus;
|
|
31
|
+
code: StreamCode;
|
|
32
|
+
leg: ActivityLeg;
|
|
33
|
+
adjacencyList: StreamData[];
|
|
34
|
+
adjacentIndex: number;
|
|
35
|
+
guidLedger: number;
|
|
36
|
+
constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
|
|
37
|
+
/** Leg 1 entry for duplex activities (Worker, Await, Cycle) */
|
|
38
|
+
verifyEntry(): Promise<void>;
|
|
39
|
+
/** Leg 2 re-entry for duplex activities; returns the activity ledger */
|
|
40
|
+
verifyReentry(): Promise<number>;
|
|
41
|
+
/** Leg 1 entry for Category B (Hook passthrough, Signal, Interrupt-target).
|
|
42
|
+
* Returns true when resuming from a prior crash (Leg1 already committed). */
|
|
43
|
+
verifyLeg1Entry(): Promise<boolean>;
|
|
44
|
+
/** Load job state from the store into `this.context` */
|
|
45
|
+
getState(): Promise<void>;
|
|
46
|
+
/** Bootstrap $self, $job refs and output.metadata.au timestamp */
|
|
47
|
+
initSelf(ctx: StringAnyType): JobState;
|
|
48
|
+
/** Resolve expire and persistent policies from config */
|
|
49
|
+
initPolicies(ctx: JobState): void;
|
|
50
|
+
/** Set the dimensional address for this activity */
|
|
51
|
+
initDimensionalAddress(dad: string): void;
|
|
52
|
+
/** Reject stale messages from a prior job generation */
|
|
53
|
+
assertGenerationalId(jobGID: string, msgGID?: string): void;
|
|
54
|
+
/** Map data INTO this activity (from other activities' outputs) */
|
|
55
|
+
mapInputData(): void;
|
|
56
|
+
/** Transform this activity's own output via output.maps */
|
|
57
|
+
mapOutputData(): void;
|
|
58
|
+
/** Promote activity data to the shared job state via job.maps */
|
|
59
|
+
mapJobData(): void;
|
|
60
|
+
/** Resolve the Dynamic Activation Control threshold (default: 0) */
|
|
61
|
+
mapStatusThreshold(): number;
|
|
62
|
+
/** Stamp job-level `ju` (job_updated) timestamp */
|
|
63
|
+
bindJobMetadata(): void;
|
|
64
|
+
/** Stamp activity-level timestamps, type, and subtype */
|
|
65
|
+
bindActivityMetadata(): void;
|
|
66
|
+
/** Flatten job-level context paths into store-ready key/values */
|
|
67
|
+
bindJobState(state: StringAnyType): Promise<void>;
|
|
68
|
+
/** Flatten activity-level context paths into store-ready key/values */
|
|
69
|
+
bindActivityState(state: StringAnyType): void;
|
|
70
|
+
/** Write the dimensional address into the state payload */
|
|
71
|
+
bindDimensionalAddress(state: StringAnyType): void;
|
|
72
|
+
/** Attach inbound data (output or hook) to the activity's context slot */
|
|
73
|
+
bindActivityData(type: 'output' | 'hook'): void;
|
|
74
|
+
/** Attach an error response to the activity's context slot */
|
|
75
|
+
bindActivityError(data: Record<string, unknown>): void;
|
|
76
|
+
/** Promote an unhandled activity error to the job level */
|
|
77
|
+
bindJobError(data: Record<string, unknown>): void;
|
|
78
|
+
/** Persist the full activity + job state in a single store call */
|
|
79
|
+
setState(txn?: ProviderTransaction): Promise<string>;
|
|
80
|
+
/** Increment/decrement the job semaphore */
|
|
81
|
+
setStatus(amount: number, txn?: ProviderTransaction): Promise<void | any>;
|
|
82
|
+
/** Build the list of child activities to transition to */
|
|
83
|
+
filterAdjacent(): Promise<StreamData[]>;
|
|
84
|
+
/** Current dimensional address (accounts for cycle offset) */
|
|
85
|
+
resolveDad(): string;
|
|
86
|
+
/** Dimensional address for children (appends seed `,0`) */
|
|
87
|
+
resolveAdjacentDad(): string;
|
|
88
|
+
/** Did the semaphore reach its threshold? (from transaction results) */
|
|
89
|
+
resolveThresholdHit(results: TransactionResultList): boolean;
|
|
90
|
+
/** Extract the job status from the last transaction result */
|
|
91
|
+
resolveStatus(multi: TransactionResultList): number;
|
|
92
|
+
/** Should this activity emit to the graph's publishes topic? */
|
|
93
|
+
shouldEmit(): boolean;
|
|
94
|
+
/** Should this activity emit completion while keeping the job alive? */
|
|
95
|
+
shouldPersistJob(): boolean;
|
|
96
|
+
isJobComplete(s: JobStatus): boolean;
|
|
97
|
+
jobWasInterrupted(s: JobStatus): boolean;
|
|
98
|
+
/** Leg 2 protocol: save → spawn → complete (duplex activities) */
|
|
99
|
+
executeStepProtocol(delta: number, shouldFinalize: boolean): Promise<boolean>;
|
|
100
|
+
/** Leg 1 protocol: save → spawn → complete (Category B activities) */
|
|
101
|
+
executeLeg1StepProtocol(delta: number): Promise<boolean>;
|
|
102
|
+
processEvent(status?: StreamStatus, code?: StreamCode, type?: 'hook' | 'output'): Promise<void>;
|
|
103
|
+
setLeg(leg: ActivityLeg): void;
|
|
104
|
+
registerTimeout(): Promise<void>;
|
|
105
|
+
getJobStatus(): null | number;
|
|
106
|
+
authorizeEntry(_state: StringAnyType): string[];
|
|
107
|
+
bindSearchData(_options?: any): void;
|
|
108
|
+
bindMarkerData(_options?: any): void;
|
|
109
|
+
/** Job metadata paths to persist (Trigger overrides with full JOB set) */
|
|
110
|
+
bindJobMetadataPaths(): string[];
|
|
111
|
+
/** Activity metadata paths to persist (Trigger overrides; leg-aware) */
|
|
112
|
+
bindActivityMetadataPaths(): string[];
|
|
113
|
+
getTriggerConfig(): Promise<ActivityType>;
|
|
114
|
+
handleProcessError(error: Error, telemetry: TelemetryService | undefined, label: string): void;
|
|
115
|
+
}
|
|
116
|
+
export { Activity, ActivityType };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Activity = void 0;
|
|
27
|
+
const errors_1 = require("../../../modules/errors");
|
|
28
|
+
const stream_1 = require("../../../types/stream");
|
|
29
|
+
const Mapping = __importStar(require("./mapping"));
|
|
30
|
+
const Context = __importStar(require("./context"));
|
|
31
|
+
const State = __importStar(require("./state"));
|
|
32
|
+
const Transition = __importStar(require("./transition"));
|
|
33
|
+
const Verify = __importStar(require("./verify"));
|
|
34
|
+
const Protocol = __importStar(require("./protocol"));
|
|
35
|
+
const Process = __importStar(require("./process"));
|
|
36
|
+
/**
|
|
37
|
+
* Base class for every node in the workflow DAG.
|
|
38
|
+
*
|
|
39
|
+
* An activity's lifecycle flows top-to-bottom through this file:
|
|
40
|
+
* enter → load state → map data → persist → transition → complete.
|
|
41
|
+
*
|
|
42
|
+
* Each section delegates to a purpose-specific module inside `activity/`.
|
|
43
|
+
* Open the module when you need implementation detail; read this file
|
|
44
|
+
* when you need the big picture.
|
|
45
|
+
*/
|
|
46
|
+
class Activity {
|
|
47
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
48
|
+
this.status = stream_1.StreamStatus.SUCCESS;
|
|
49
|
+
this.code = 200;
|
|
50
|
+
this.adjacentIndex = 0;
|
|
51
|
+
this.guidLedger = 0;
|
|
52
|
+
this.config = config;
|
|
53
|
+
this.data = data;
|
|
54
|
+
this.metadata = metadata;
|
|
55
|
+
this.hook = hook;
|
|
56
|
+
this.engine = engine;
|
|
57
|
+
this.context = context || { data: {}, metadata: {} };
|
|
58
|
+
this.logger = engine.logger;
|
|
59
|
+
this.store = engine.store;
|
|
60
|
+
}
|
|
61
|
+
// ═════════════════════════════════════════════════════════════════
|
|
62
|
+
// 1. ENTER — verify this activity is allowed to run
|
|
63
|
+
// Guards against stale messages, duplicate deliveries,
|
|
64
|
+
// and inactive jobs. Sets the execution leg.
|
|
65
|
+
// → see verify.ts
|
|
66
|
+
// ═════════════════════════════════════════════════════════════════
|
|
67
|
+
/** Leg 1 entry for duplex activities (Worker, Await, Cycle) */
|
|
68
|
+
async verifyEntry() {
|
|
69
|
+
return Verify.verifyEntry(this);
|
|
70
|
+
}
|
|
71
|
+
/** Leg 2 re-entry for duplex activities; returns the activity ledger */
|
|
72
|
+
async verifyReentry() {
|
|
73
|
+
return Verify.verifyReentry(this);
|
|
74
|
+
}
|
|
75
|
+
/** Leg 1 entry for Category B (Hook passthrough, Signal, Interrupt-target).
|
|
76
|
+
* Returns true when resuming from a prior crash (Leg1 already committed). */
|
|
77
|
+
async verifyLeg1Entry() {
|
|
78
|
+
return Verify.verifyLeg1Entry(this);
|
|
79
|
+
}
|
|
80
|
+
// ═════════════════════════════════════════════════════════════════
|
|
81
|
+
// 2. LOAD / INITIALIZE — hydrate job state from the store
|
|
82
|
+
// Reads the hash, restores the context tree, validates
|
|
83
|
+
// the generational ID, and initializes $self / policies.
|
|
84
|
+
// → see state.ts (getState) and context.ts
|
|
85
|
+
// ═════════════════════════════════════════════════════════════════
|
|
86
|
+
/** Load job state from the store into `this.context` */
|
|
87
|
+
async getState() {
|
|
88
|
+
return State.getState(this);
|
|
89
|
+
}
|
|
90
|
+
/** Bootstrap $self, $job refs and output.metadata.au timestamp */
|
|
91
|
+
initSelf(ctx) {
|
|
92
|
+
return Context.initSelf(this, ctx);
|
|
93
|
+
}
|
|
94
|
+
/** Resolve expire and persistent policies from config */
|
|
95
|
+
initPolicies(ctx) {
|
|
96
|
+
Context.initPolicies(this, ctx);
|
|
97
|
+
}
|
|
98
|
+
/** Set the dimensional address for this activity */
|
|
99
|
+
initDimensionalAddress(dad) {
|
|
100
|
+
Context.initDimensionalAddress(this, dad);
|
|
101
|
+
}
|
|
102
|
+
/** Reject stale messages from a prior job generation */
|
|
103
|
+
assertGenerationalId(jobGID, msgGID) {
|
|
104
|
+
Context.assertGenerationalId(jobGID, msgGID, this.context);
|
|
105
|
+
}
|
|
106
|
+
// ═════════════════════════════════════════════════════════════════
|
|
107
|
+
// 3. MAP — transform data between activities and the job
|
|
108
|
+
// Evaluates @pipe expressions in the YAML `maps` config
|
|
109
|
+
// to move data in (input), out (output), and to the job.
|
|
110
|
+
// → see mapping.ts
|
|
111
|
+
// ═════════════════════════════════════════════════════════════════
|
|
112
|
+
/** Map data INTO this activity (from other activities' outputs) */
|
|
113
|
+
mapInputData() {
|
|
114
|
+
Mapping.mapInputData(this);
|
|
115
|
+
}
|
|
116
|
+
/** Transform this activity's own output via output.maps */
|
|
117
|
+
mapOutputData() {
|
|
118
|
+
Mapping.mapOutputData(this);
|
|
119
|
+
}
|
|
120
|
+
/** Promote activity data to the shared job state via job.maps */
|
|
121
|
+
mapJobData() {
|
|
122
|
+
Mapping.mapJobData(this);
|
|
123
|
+
}
|
|
124
|
+
/** Resolve the Dynamic Activation Control threshold (default: 0) */
|
|
125
|
+
mapStatusThreshold() {
|
|
126
|
+
return Mapping.mapStatusThreshold(this);
|
|
127
|
+
}
|
|
128
|
+
// ═════════════════════════════════════════════════════════════════
|
|
129
|
+
// 4. BIND — prepare context fields for persistence
|
|
130
|
+
// Stamps metadata, flattens the context tree into key/value
|
|
131
|
+
// pairs, and attaches error or hook data.
|
|
132
|
+
// → see state.ts (bind*) and context.ts (bindActivity*)
|
|
133
|
+
// ═════════════════════════════════════════════════════════════════
|
|
134
|
+
/** Stamp job-level `ju` (job_updated) timestamp */
|
|
135
|
+
bindJobMetadata() {
|
|
136
|
+
State.bindJobMetadata(this);
|
|
137
|
+
}
|
|
138
|
+
/** Stamp activity-level timestamps, type, and subtype */
|
|
139
|
+
bindActivityMetadata() {
|
|
140
|
+
State.bindActivityMetadata(this);
|
|
141
|
+
}
|
|
142
|
+
/** Flatten job-level context paths into store-ready key/values */
|
|
143
|
+
async bindJobState(state) {
|
|
144
|
+
return State.bindJobState(this, state);
|
|
145
|
+
}
|
|
146
|
+
/** Flatten activity-level context paths into store-ready key/values */
|
|
147
|
+
bindActivityState(state) {
|
|
148
|
+
State.bindActivityState(this, state);
|
|
149
|
+
}
|
|
150
|
+
/** Write the dimensional address into the state payload */
|
|
151
|
+
bindDimensionalAddress(state) {
|
|
152
|
+
State.bindDimensionalAddress(this, state);
|
|
153
|
+
}
|
|
154
|
+
/** Attach inbound data (output or hook) to the activity's context slot */
|
|
155
|
+
bindActivityData(type) {
|
|
156
|
+
Context.bindActivityData(this, type);
|
|
157
|
+
}
|
|
158
|
+
/** Attach an error response to the activity's context slot */
|
|
159
|
+
bindActivityError(data) {
|
|
160
|
+
Context.bindActivityError(this, data);
|
|
161
|
+
}
|
|
162
|
+
/** Promote an unhandled activity error to the job level */
|
|
163
|
+
bindJobError(data) {
|
|
164
|
+
Context.bindJobError(this, data);
|
|
165
|
+
}
|
|
166
|
+
// ═════════════════════════════════════════════════════════════════
|
|
167
|
+
// 5. PERSIST — write state to the store
|
|
168
|
+
// Orchestrates bind → flatten → store.setState in one call.
|
|
169
|
+
// Also handles the job semaphore (setStatus).
|
|
170
|
+
// → see state.ts
|
|
171
|
+
// ═════════════════════════════════════════════════════════════════
|
|
172
|
+
/** Persist the full activity + job state in a single store call */
|
|
173
|
+
async setState(txn) {
|
|
174
|
+
return State.setState(this, txn);
|
|
175
|
+
}
|
|
176
|
+
/** Increment/decrement the job semaphore */
|
|
177
|
+
async setStatus(amount, txn) {
|
|
178
|
+
return State.setStatus(this, amount, txn);
|
|
179
|
+
}
|
|
180
|
+
// ═════════════════════════════════════════════════════════════════
|
|
181
|
+
// 6. TRANSITION — resolve which children run next
|
|
182
|
+
// Evaluates transition rules, checks job completion,
|
|
183
|
+
// and builds the adjacency list for the step protocol.
|
|
184
|
+
// → see transition.ts and context.ts (resolveDad)
|
|
185
|
+
// ═════════════════════════════════════════════════════════════════
|
|
186
|
+
/** Build the list of child activities to transition to */
|
|
187
|
+
async filterAdjacent() {
|
|
188
|
+
return Transition.filterAdjacent(this);
|
|
189
|
+
}
|
|
190
|
+
/** Current dimensional address (accounts for cycle offset) */
|
|
191
|
+
resolveDad() {
|
|
192
|
+
return Context.resolveDad(this);
|
|
193
|
+
}
|
|
194
|
+
/** Dimensional address for children (appends seed `,0`) */
|
|
195
|
+
resolveAdjacentDad() {
|
|
196
|
+
return Context.resolveAdjacentDad(this);
|
|
197
|
+
}
|
|
198
|
+
/** Did the semaphore reach its threshold? (from transaction results) */
|
|
199
|
+
resolveThresholdHit(results) {
|
|
200
|
+
return Transition.resolveThresholdHit(results);
|
|
201
|
+
}
|
|
202
|
+
/** Extract the job status from the last transaction result */
|
|
203
|
+
resolveStatus(multi) {
|
|
204
|
+
return Transition.resolveStatus(multi);
|
|
205
|
+
}
|
|
206
|
+
/** Should this activity emit to the graph's publishes topic? */
|
|
207
|
+
shouldEmit() {
|
|
208
|
+
return Transition.shouldEmit(this);
|
|
209
|
+
}
|
|
210
|
+
/** Should this activity emit completion while keeping the job alive? */
|
|
211
|
+
shouldPersistJob() {
|
|
212
|
+
return Transition.shouldPersistJob(this);
|
|
213
|
+
}
|
|
214
|
+
isJobComplete(s) {
|
|
215
|
+
return Transition.isJobComplete(s);
|
|
216
|
+
}
|
|
217
|
+
jobWasInterrupted(s) {
|
|
218
|
+
return Transition.jobWasInterrupted(s);
|
|
219
|
+
}
|
|
220
|
+
// ═════════════════════════════════════════════════════════════════
|
|
221
|
+
// 7. COMMIT — crash-safe 3-step protocols
|
|
222
|
+
// Each protocol runs three atomic transactions:
|
|
223
|
+
// save work → spawn children + semaphore → completion tasks.
|
|
224
|
+
// GUID ledger digits allow crash-resume at any step.
|
|
225
|
+
// → see protocol.ts
|
|
226
|
+
// ═════════════════════════════════════════════════════════════════
|
|
227
|
+
/** Leg 2 protocol: save → spawn → complete (duplex activities) */
|
|
228
|
+
async executeStepProtocol(delta, shouldFinalize) {
|
|
229
|
+
return Protocol.executeStepProtocol(this, delta, shouldFinalize);
|
|
230
|
+
}
|
|
231
|
+
/** Leg 1 protocol: save → spawn → complete (Category B activities) */
|
|
232
|
+
async executeLeg1StepProtocol(delta) {
|
|
233
|
+
return Protocol.executeLeg1StepProtocol(this, delta);
|
|
234
|
+
}
|
|
235
|
+
// ═════════════════════════════════════════════════════════════════
|
|
236
|
+
// 8. DUPLEX RE-ENTRY — handle Leg 2 responses
|
|
237
|
+
// Called when a worker/await/hook returns its result.
|
|
238
|
+
// Binds the response, maps job data, and runs the protocol.
|
|
239
|
+
// → see process.ts
|
|
240
|
+
// ═════════════════════════════════════════════════════════════════
|
|
241
|
+
async processEvent(status = stream_1.StreamStatus.SUCCESS, code = 200, type = 'output') {
|
|
242
|
+
return Process.processEvent(this, status, code, type);
|
|
243
|
+
}
|
|
244
|
+
// ═════════════════════════════════════════════════════════════════
|
|
245
|
+
// OVERRIDABLE — stubs replaced by specific activity types
|
|
246
|
+
// ═════════════════════════════════════════════════════════════════
|
|
247
|
+
setLeg(leg) { this.leg = leg; }
|
|
248
|
+
async registerTimeout() { }
|
|
249
|
+
getJobStatus() { return null; }
|
|
250
|
+
authorizeEntry(_state) { return []; }
|
|
251
|
+
bindSearchData(_options) { }
|
|
252
|
+
bindMarkerData(_options) { }
|
|
253
|
+
/** Job metadata paths to persist (Trigger overrides with full JOB set) */
|
|
254
|
+
bindJobMetadataPaths() {
|
|
255
|
+
return State.bindJobMetadataPaths();
|
|
256
|
+
}
|
|
257
|
+
/** Activity metadata paths to persist (Trigger overrides; leg-aware) */
|
|
258
|
+
bindActivityMetadataPaths() {
|
|
259
|
+
return State.bindActivityMetadataPaths(this.leg);
|
|
260
|
+
}
|
|
261
|
+
async getTriggerConfig() {
|
|
262
|
+
return await this.store.getSchema(this.config.trigger, await this.engine.getVID());
|
|
263
|
+
}
|
|
264
|
+
// ═════════════════════════════════════════════════════════════════
|
|
265
|
+
// ERROR — shared catch handler for subclass process() methods
|
|
266
|
+
// Swallows expected concurrency errors (stale job, duplicate
|
|
267
|
+
// delivery, generational mismatch) and re-throws the rest.
|
|
268
|
+
// ═════════════════════════════════════════════════════════════════
|
|
269
|
+
handleProcessError(error, telemetry, label) {
|
|
270
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
271
|
+
this.logger.error(`${label}-inactive-job-error`, { error });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
275
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
279
|
+
this.logger.error(`${label}-get-state-error`, { error });
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
else if (error instanceof errors_1.CollationError) {
|
|
283
|
+
if (error.fault === 'duplicate') {
|
|
284
|
+
this.logger.info(`${label}-collation-overage`, {
|
|
285
|
+
job_id: this.context.metadata.jid,
|
|
286
|
+
guid: this.context.metadata.guid,
|
|
287
|
+
});
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
this.logger.error(`${label}-collation-error`, { error });
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.logger.error(`${label}-process-error`, { error });
|
|
294
|
+
}
|
|
295
|
+
telemetry?.setActivityError(error.message);
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
exports.Activity = Activity;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActivityType, ActivityMetadata } from '../../../types/activity';
|
|
2
|
+
import { JobState } from '../../../types/job';
|
|
3
|
+
interface MappingContext {
|
|
4
|
+
config: ActivityType;
|
|
5
|
+
context: JobState;
|
|
6
|
+
metadata: ActivityMetadata;
|
|
7
|
+
}
|
|
8
|
+
export declare function mapInputData(instance: MappingContext): void;
|
|
9
|
+
export declare function mapOutputData(instance: MappingContext): void;
|
|
10
|
+
export declare function mapJobData(instance: MappingContext): void;
|
|
11
|
+
export declare function mapStatusThreshold(instance: MappingContext): number;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapStatusThreshold = exports.mapJobData = exports.mapOutputData = exports.mapInputData = void 0;
|
|
4
|
+
const utils_1 = require("../../../modules/utils");
|
|
5
|
+
const mapper_1 = require("../../mapper");
|
|
6
|
+
const pipe_1 = require("../../pipe");
|
|
7
|
+
function mapInputData(instance) {
|
|
8
|
+
if (instance.config.input?.maps) {
|
|
9
|
+
const mapper = new mapper_1.MapperService((0, utils_1.deepCopy)(instance.config.input.maps), instance.context);
|
|
10
|
+
instance.context.data = mapper.mapRules();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.mapInputData = mapInputData;
|
|
14
|
+
function mapOutputData(instance) {
|
|
15
|
+
if (instance.config.output?.maps) {
|
|
16
|
+
const mapper = new mapper_1.MapperService((0, utils_1.deepCopy)(instance.config.output.maps), instance.context);
|
|
17
|
+
const actOutData = mapper.mapRules();
|
|
18
|
+
const activityId = instance.metadata.aid;
|
|
19
|
+
const data = { ...instance.context[activityId].output, ...actOutData };
|
|
20
|
+
instance.context[activityId].output.data = data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.mapOutputData = mapOutputData;
|
|
24
|
+
function mapJobData(instance) {
|
|
25
|
+
if (instance.config.job?.maps) {
|
|
26
|
+
const mapper = new mapper_1.MapperService((0, utils_1.deepCopy)(instance.config.job.maps), instance.context);
|
|
27
|
+
const output = mapper.mapRules();
|
|
28
|
+
if (output) {
|
|
29
|
+
for (const key in output) {
|
|
30
|
+
const f1 = key.indexOf('[');
|
|
31
|
+
if (f1 > -1) {
|
|
32
|
+
const amount = key.substring(f1 + 1).split(']')[0];
|
|
33
|
+
if (!isNaN(Number(amount))) {
|
|
34
|
+
const left = key.substring(0, f1);
|
|
35
|
+
output[left] = output[key];
|
|
36
|
+
delete output[key];
|
|
37
|
+
}
|
|
38
|
+
else if (amount === '-' || amount === '_') {
|
|
39
|
+
const obj = output[key];
|
|
40
|
+
if (obj && typeof obj === 'object') {
|
|
41
|
+
Object.keys(obj).forEach((newKey) => {
|
|
42
|
+
output[newKey] = obj[newKey];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
delete output[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
instance.context.data = output;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.mapJobData = mapJobData;
|
|
54
|
+
function mapStatusThreshold(instance) {
|
|
55
|
+
if (instance.config.statusThreshold !== undefined) {
|
|
56
|
+
const threshold = pipe_1.Pipe.resolve(instance.config.statusThreshold, instance.context);
|
|
57
|
+
if (threshold !== undefined && !isNaN(Number(threshold))) {
|
|
58
|
+
return threshold;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
exports.mapStatusThreshold = mapStatusThreshold;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EngineService } from '../../engine';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { ActivityData, ActivityLeg, ActivityMetadata, ActivityType } from '../../../types/activity';
|
|
4
|
+
import { JobState } from '../../../types/job';
|
|
5
|
+
import { StreamCode, StreamData, StreamStatus } from '../../../types/stream';
|
|
6
|
+
interface ProcessContext {
|
|
7
|
+
config: ActivityType;
|
|
8
|
+
context: JobState;
|
|
9
|
+
metadata: ActivityMetadata;
|
|
10
|
+
engine: EngineService;
|
|
11
|
+
logger: ILogger;
|
|
12
|
+
status: StreamStatus;
|
|
13
|
+
code: StreamCode;
|
|
14
|
+
data: ActivityData;
|
|
15
|
+
leg: ActivityLeg;
|
|
16
|
+
adjacencyList: StreamData[];
|
|
17
|
+
adjacentIndex: number;
|
|
18
|
+
setLeg(leg: ActivityLeg): void;
|
|
19
|
+
verifyReentry(): Promise<number>;
|
|
20
|
+
bindActivityError(data: Record<string, unknown>): void;
|
|
21
|
+
bindActivityData(type: 'output' | 'hook'): void;
|
|
22
|
+
bindJobError(data: Record<string, unknown>): void;
|
|
23
|
+
filterAdjacent(): Promise<StreamData[]>;
|
|
24
|
+
mapJobData(): void;
|
|
25
|
+
executeStepProtocol(delta: number, shouldFinalize: boolean): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
export declare function processEvent(instance: ProcessContext, status?: StreamStatus, code?: StreamCode, type?: 'hook' | 'output'): Promise<void>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processEvent = void 0;
|
|
4
|
+
const enums_1 = require("../../../modules/enums");
|
|
5
|
+
const errors_1 = require("../../../modules/errors");
|
|
6
|
+
const collator_1 = require("../../collator");
|
|
7
|
+
const telemetry_1 = require("../../telemetry");
|
|
8
|
+
const stream_1 = require("../../../types/stream");
|
|
9
|
+
async function processEvent(instance, status = stream_1.StreamStatus.SUCCESS, code = 200, type = 'output') {
|
|
10
|
+
instance.setLeg(2);
|
|
11
|
+
const jid = instance.context.metadata.jid;
|
|
12
|
+
if (!jid) {
|
|
13
|
+
instance.logger.error('activity-process-event-error', {
|
|
14
|
+
message: 'job id is undefined',
|
|
15
|
+
});
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const aid = instance.metadata.aid;
|
|
19
|
+
instance.status = status;
|
|
20
|
+
instance.code = code;
|
|
21
|
+
instance.logger.debug('activity-process-event', {
|
|
22
|
+
topic: instance.config.subtype,
|
|
23
|
+
jid,
|
|
24
|
+
aid,
|
|
25
|
+
status,
|
|
26
|
+
code,
|
|
27
|
+
});
|
|
28
|
+
let telemetry;
|
|
29
|
+
try {
|
|
30
|
+
const collationKey = await instance.verifyReentry();
|
|
31
|
+
instance.adjacentIndex =
|
|
32
|
+
collator_1.CollatorService.getDimensionalIndex(collationKey);
|
|
33
|
+
telemetry = new telemetry_1.TelemetryService(instance.engine.appId, instance.config, instance.metadata, instance.context);
|
|
34
|
+
telemetry.startActivitySpan(instance.leg);
|
|
35
|
+
//bind data per status type
|
|
36
|
+
if (status === stream_1.StreamStatus.ERROR) {
|
|
37
|
+
instance.bindActivityError(instance.data);
|
|
38
|
+
instance.adjacencyList = await instance.filterAdjacent();
|
|
39
|
+
if (!instance.adjacencyList.length) {
|
|
40
|
+
instance.bindJobError(instance.data);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
instance.bindActivityData(type);
|
|
45
|
+
instance.adjacencyList = await instance.filterAdjacent();
|
|
46
|
+
}
|
|
47
|
+
instance.mapJobData();
|
|
48
|
+
//mark unrecoverable errors as terminal
|
|
49
|
+
if (status === stream_1.StreamStatus.ERROR && !instance.adjacencyList?.length) {
|
|
50
|
+
if (!instance.context.data)
|
|
51
|
+
instance.context.data = {};
|
|
52
|
+
instance.context.data.done = true;
|
|
53
|
+
instance.context.data.$error = {
|
|
54
|
+
message: instance.data?.message || 'unknown error',
|
|
55
|
+
code: enums_1.HMSH_CODE_DURABLE_MAXED,
|
|
56
|
+
stack: instance.data?.stack,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const delta = status === stream_1.StreamStatus.PENDING
|
|
60
|
+
? instance.adjacencyList.length
|
|
61
|
+
: instance.adjacencyList.length - 1;
|
|
62
|
+
const shouldFinalize = status !== stream_1.StreamStatus.PENDING;
|
|
63
|
+
await instance.executeStepProtocol(delta, shouldFinalize);
|
|
64
|
+
telemetry.mapActivityAttributes();
|
|
65
|
+
telemetry.setActivityAttributes({});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof errors_1.CollationError) {
|
|
69
|
+
instance.logger.info(`process-event-${error.fault}-error`, { error });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
else if (error instanceof errors_1.InactiveJobError) {
|
|
73
|
+
instance.logger.info('process-event-inactive-job-error', { error });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
77
|
+
instance.logger.info('process-event-generational-job-error', {
|
|
78
|
+
error,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
83
|
+
instance.logger.info('process-event-get-job-error', { error });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
instance.logger.error('activity-process-event-error', {
|
|
87
|
+
error,
|
|
88
|
+
message: error.message,
|
|
89
|
+
stack: error.stack,
|
|
90
|
+
name: error.name,
|
|
91
|
+
});
|
|
92
|
+
telemetry?.setActivityError(error.message);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
telemetry?.endActivitySpan();
|
|
97
|
+
instance.logger.debug('activity-process-event-end', { jid, aid });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.processEvent = processEvent;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EngineService } from '../../engine';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { StoreService } from '../../store';
|
|
4
|
+
import { ActivityMetadata, ActivityType } from '../../../types/activity';
|
|
5
|
+
import { ProviderClient, ProviderTransaction, TransactionResultList } from '../../../types/provider';
|
|
6
|
+
import { JobState } from '../../../types/job';
|
|
7
|
+
import { StreamData } from '../../../types/stream';
|
|
8
|
+
interface ProtocolContext {
|
|
9
|
+
config: ActivityType;
|
|
10
|
+
context: JobState;
|
|
11
|
+
metadata: ActivityMetadata;
|
|
12
|
+
store: StoreService<ProviderClient, ProviderTransaction>;
|
|
13
|
+
engine: EngineService;
|
|
14
|
+
logger: ILogger;
|
|
15
|
+
adjacencyList: StreamData[];
|
|
16
|
+
adjacentIndex: number;
|
|
17
|
+
guidLedger: number;
|
|
18
|
+
mapStatusThreshold(): number;
|
|
19
|
+
setState(txn?: ProviderTransaction): Promise<string>;
|
|
20
|
+
shouldEmit(): boolean;
|
|
21
|
+
shouldPersistJob(): boolean;
|
|
22
|
+
resolveThresholdHit(results: TransactionResultList): boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 3-step Leg2 protocol using GUID ledger for crash-safe resume.
|
|
26
|
+
* Each step bundles durable writes with its concluding digit
|
|
27
|
+
* update in a single transaction.
|
|
28
|
+
*/
|
|
29
|
+
export declare function executeStepProtocol(instance: ProtocolContext, delta: number, shouldFinalize: boolean): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* 3-step Leg1 protocol for Category B activities
|
|
32
|
+
* (Leg1-only with children: Hook passthrough, Signal, Interrupt-another).
|
|
33
|
+
*
|
|
34
|
+
* Step A: setState + Leg1 completion + step1 marker
|
|
35
|
+
* Step B: publish children + semaphore + edge capture
|
|
36
|
+
* Step C: if edge → completion tasks + finalize
|
|
37
|
+
*/
|
|
38
|
+
export declare function executeLeg1StepProtocol(instance: ProtocolContext, delta: number): Promise<boolean>;
|
|
39
|
+
export {};
|