@hotmeshio/hotmesh 0.12.1 → 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 -2
- package/build/modules/errors.js +17 -1
- package/build/modules/storage.d.ts +1 -0
- package/build/modules/storage.js +2 -1
- package/build/package.json +8 -2
- 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/dba/index.d.ts +14 -4
- package/build/services/dba/index.js +57 -18
- package/build/services/durable/activity.d.ts +30 -0
- package/build/services/durable/activity.js +46 -0
- package/build/services/durable/client.d.ts +26 -31
- package/build/services/durable/client.js +26 -31
- package/build/services/durable/connection.d.ts +13 -7
- package/build/services/durable/connection.js +13 -7
- package/build/services/durable/exporter.d.ts +2 -2
- package/build/services/durable/exporter.js +27 -12
- package/build/services/durable/handle.d.ts +59 -41
- package/build/services/durable/handle.js +61 -41
- package/build/services/durable/index.d.ts +152 -283
- package/build/services/durable/index.js +161 -289
- 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 +2 -3
- package/build/services/durable/schemas/factory.js +180 -30
- 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 +314 -60
- 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 +2 -2
- package/build/services/durable/workflow/didRun.js +4 -4
- 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 +51 -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 +142 -533
- package/build/services/hotmesh/index.js +223 -674
- 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/dba.d.ts +39 -3
- package/build/types/durable.d.ts +123 -25
- package/build/types/error.d.ts +10 -0
- package/build/types/exporter.d.ts +1 -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 +8 -2
- 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
|
@@ -54,7 +54,7 @@ declare class ExporterService {
|
|
|
54
54
|
*/
|
|
55
55
|
export(jobId: string, options?: ExportOptions): Promise<DurableJobExport>;
|
|
56
56
|
/**
|
|
57
|
-
* Export a workflow execution as a
|
|
57
|
+
* Export a workflow execution as a structured event history.
|
|
58
58
|
*
|
|
59
59
|
* **Sparse mode** (default): transforms the main workflow's timeline
|
|
60
60
|
* into a flat event list. No additional I/O beyond the initial export.
|
|
@@ -80,7 +80,7 @@ declare class ExporterService {
|
|
|
80
80
|
private resolveSymbolField;
|
|
81
81
|
/**
|
|
82
82
|
* Pure transformation: convert a raw DurableJobExport into a
|
|
83
|
-
*
|
|
83
|
+
* WorkflowExecution event history.
|
|
84
84
|
*/
|
|
85
85
|
transformToExecution(raw: DurableJobExport, workflowId: string, workflowTopic: string, options: ExecutionExportOptions): WorkflowExecution;
|
|
86
86
|
/**
|
|
@@ -173,7 +173,7 @@ class ExporterService {
|
|
|
173
173
|
return jobExport;
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
|
-
* Export a workflow execution as a
|
|
176
|
+
* Export a workflow execution as a structured event history.
|
|
177
177
|
*
|
|
178
178
|
* **Sparse mode** (default): transforms the main workflow's timeline
|
|
179
179
|
* into a flat event list. No additional I/O beyond the initial export.
|
|
@@ -510,28 +510,43 @@ class ExporterService {
|
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
|
-
// ── 3. Stream-based
|
|
514
|
-
//
|
|
513
|
+
// ── 3. Stream-based enrichment from worker_streams ──
|
|
514
|
+
// Fetches worker invocation messages to recover:
|
|
515
|
+
// - Workflow input arguments (for workflow_execution_started)
|
|
516
|
+
// - Activity inputs when job attributes have been pruned
|
|
515
517
|
if (this.store.getStreamHistory) {
|
|
516
|
-
const
|
|
518
|
+
const unenrichedActivityEvents = execution.events.filter((e) => (e.event_type === 'activity_task_scheduled' ||
|
|
517
519
|
e.event_type === 'activity_task_completed' ||
|
|
518
520
|
e.event_type === 'activity_task_failed') &&
|
|
519
521
|
e.attributes.input === undefined);
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
522
|
+
const startedEvent = execution.events.find((e) => e.event_type === 'workflow_execution_started');
|
|
523
|
+
const startedNeedsInput = startedEvent &&
|
|
524
|
+
(!(startedEvent.attributes.input) ||
|
|
525
|
+
Object.keys(startedEvent.attributes.input).length === 0);
|
|
526
|
+
if (unenrichedActivityEvents.length > 0 || startedNeedsInput) {
|
|
527
|
+
const streamHistory = await this.store.getStreamHistory(workflowId);
|
|
524
528
|
// Build a map of aid -> stream message data (the worker invocation inputs)
|
|
525
529
|
const streamInputsByAid = new Map();
|
|
526
530
|
for (const entry of streamHistory) {
|
|
527
|
-
if (entry.
|
|
531
|
+
if (entry.data) {
|
|
528
532
|
const key = `${entry.aid}:${entry.dad || ''}`;
|
|
529
533
|
if (!streamInputsByAid.has(key)) {
|
|
530
534
|
streamInputsByAid.set(key, entry.data);
|
|
531
535
|
}
|
|
532
536
|
}
|
|
533
537
|
}
|
|
534
|
-
|
|
538
|
+
// Enrich workflow_execution_started with input arguments from the
|
|
539
|
+
// first worker invocation message (aid="worker", data.arguments=[...])
|
|
540
|
+
if (startedNeedsInput) {
|
|
541
|
+
const workerEntry = streamHistory.find((entry) => entry.aid === 'worker' &&
|
|
542
|
+
entry.jid === workflowId &&
|
|
543
|
+
entry.data?.arguments);
|
|
544
|
+
if (workerEntry) {
|
|
545
|
+
startedEvent.attributes.input = workerEntry.data.arguments;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// Enrich unenriched activity events
|
|
549
|
+
for (const evt of unenrichedActivityEvents) {
|
|
535
550
|
const attrs = evt.attributes;
|
|
536
551
|
// Try matching by activity_type + dimensional address
|
|
537
552
|
const key = `${attrs.activity_type}:${attrs.timeline_key || ''}`;
|
|
@@ -571,7 +586,7 @@ class ExporterService {
|
|
|
571
586
|
}
|
|
572
587
|
/**
|
|
573
588
|
* Pure transformation: convert a raw DurableJobExport into a
|
|
574
|
-
*
|
|
589
|
+
* WorkflowExecution event history.
|
|
575
590
|
*/
|
|
576
591
|
transformToExecution(raw, workflowId, workflowTopic, options) {
|
|
577
592
|
const events = [];
|
|
@@ -761,7 +776,7 @@ class ExporterService {
|
|
|
761
776
|
for (let i = 0; i < events.length; i++) {
|
|
762
777
|
events[i].event_id = i + 1;
|
|
763
778
|
}
|
|
764
|
-
// ── Back-references
|
|
779
|
+
// ── Back-references ────────────────────────────────────────
|
|
765
780
|
const scheduledMap = new Map();
|
|
766
781
|
const initiatedMap = new Map();
|
|
767
782
|
for (const e of events) {
|
|
@@ -4,28 +4,24 @@ import { JobInterruptOptions } from '../../types/job';
|
|
|
4
4
|
import { StreamError } from '../../types/stream';
|
|
5
5
|
import { ExporterService } from './exporter';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* workflow.
|
|
9
|
-
* querying the state of the workflow. It is instanced/accessed via the
|
|
10
|
-
* Durable.Client class.
|
|
7
|
+
* Handle to a running or completed workflow execution. Returned by
|
|
8
|
+
* `client.workflow.start()` and `client.workflow.getHandle()`.
|
|
11
9
|
*
|
|
12
10
|
* @example
|
|
13
11
|
* ```typescript
|
|
14
|
-
* import { Client } from '@hotmeshio/hotmesh';
|
|
15
|
-
* import { Client as Postgres } from 'pg';
|
|
16
|
-
*
|
|
17
|
-
* const client = new Client({ connection: {
|
|
18
|
-
* class: Postgres,
|
|
19
|
-
* options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
|
|
20
|
-
* }});
|
|
21
|
-
*
|
|
22
12
|
* const handle = await client.workflow.start({
|
|
23
|
-
*
|
|
24
|
-
*
|
|
13
|
+
* args: ['order-123'],
|
|
14
|
+
* taskQueue: 'orders',
|
|
15
|
+
* workflowName: 'orderWorkflow',
|
|
16
|
+
* workflowId: Durable.guid(),
|
|
25
17
|
* });
|
|
26
18
|
*
|
|
27
|
-
* //
|
|
28
|
-
* await handle.
|
|
19
|
+
* // Await the final result
|
|
20
|
+
* const result = await handle.result();
|
|
21
|
+
*
|
|
22
|
+
* // Or interact while running
|
|
23
|
+
* await handle.signal('approval', { approved: true });
|
|
24
|
+
* await handle.cancel();
|
|
29
25
|
* ```
|
|
30
26
|
*/
|
|
31
27
|
export declare class WorkflowHandleService {
|
|
@@ -41,11 +37,12 @@ export declare class WorkflowHandleService {
|
|
|
41
37
|
*/
|
|
42
38
|
constructor(hotMesh: HotMesh, workflowTopic: string, workflowId: string);
|
|
43
39
|
/**
|
|
44
|
-
* Exports the workflow state
|
|
40
|
+
* Exports the full workflow state (job hash, metadata, activity
|
|
41
|
+
* results) as a JSON object.
|
|
45
42
|
*/
|
|
46
43
|
export(options?: ExportOptions): Promise<DurableJobExport>;
|
|
47
44
|
/**
|
|
48
|
-
* Exports the workflow as
|
|
45
|
+
* Exports the workflow as an execution event history.
|
|
49
46
|
*
|
|
50
47
|
* **Sparse mode** (default): transforms the main workflow's timeline
|
|
51
48
|
* into a flat event list with workflow lifecycle, activity, child workflow,
|
|
@@ -56,43 +53,64 @@ export declare class WorkflowHandleService {
|
|
|
56
53
|
*/
|
|
57
54
|
exportExecution(options?: ExecutionExportOptions): Promise<WorkflowExecution>;
|
|
58
55
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
56
|
+
* Delivers a named signal to the workflow. If the workflow is paused
|
|
57
|
+
* on `Durable.workflow.condition(signalId)`, it resumes with the
|
|
58
|
+
* provided data.
|
|
59
|
+
*
|
|
60
|
+
* @param signalId - Matches the `signalId` passed to `condition()`.
|
|
61
|
+
* @param data - Payload delivered to the waiting workflow.
|
|
63
62
|
*/
|
|
64
63
|
signal(signalId: string, data: Record<any, any>): Promise<void>;
|
|
65
64
|
/**
|
|
66
|
-
* Returns the
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
65
|
+
* Returns the current workflow state. For a completed workflow this
|
|
66
|
+
* is the final output; for a running workflow it reflects the latest
|
|
67
|
+
* persisted state (may change as activities complete).
|
|
68
|
+
*
|
|
69
|
+
* @param metadata - If `true`, returns the full job envelope including
|
|
70
|
+
* internal metadata alongside the data.
|
|
70
71
|
*/
|
|
71
72
|
state(metadata?: boolean): Promise<Record<string, any>>;
|
|
72
73
|
/**
|
|
73
|
-
* Returns
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* to
|
|
74
|
+
* Returns key-value pairs previously written via
|
|
75
|
+
* `Durable.workflow.search()` or `Durable.workflow.enrich()`.
|
|
76
|
+
*
|
|
77
|
+
* @param fields - The field names to retrieve.
|
|
77
78
|
*/
|
|
78
79
|
queryState(fields: string[]): Promise<Record<string, any>>;
|
|
79
80
|
/**
|
|
80
|
-
* Returns the
|
|
81
|
-
*
|
|
82
|
-
* 0 is complete and a negative value represents that the flow was
|
|
83
|
-
* interrupted.
|
|
81
|
+
* Returns the workflow's numeric status code: `0` = completed,
|
|
82
|
+
* positive = still running, negative = interrupted/errored.
|
|
84
83
|
*/
|
|
85
84
|
status(): Promise<number>;
|
|
86
85
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* Immediately terminates the workflow. The job is marked as interrupted,
|
|
87
|
+
* subscribers are notified, and the job hash is expired. Unlike
|
|
88
|
+
* {@link cancel}, this does **not** give the workflow a chance to
|
|
89
|
+
* run cleanup code.
|
|
89
90
|
*/
|
|
90
|
-
|
|
91
|
+
terminate(options?: JobInterruptOptions): Promise<string>;
|
|
91
92
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
93
|
+
* Requests cooperative cancellation of the workflow. Unlike
|
|
94
|
+
* `terminate()` (which terminates immediately), `cancel()` sets
|
|
95
|
+
* a durable flag that the workflow detects at its next durable
|
|
96
|
+
* operation (`sleep`, `proxyActivities`, `executeChild`, etc.).
|
|
97
|
+
* The workflow receives a `CancelledFailure` error that it can
|
|
98
|
+
* catch to perform cleanup before exiting.
|
|
99
|
+
*
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const handle = await client.workflow.start({ ... });
|
|
102
|
+
* await handle.cancel();
|
|
103
|
+
* // Workflow will throw CancelledFailure at its next durable operation
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
cancel(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Blocks until the workflow completes and returns the result. If the
|
|
109
|
+
* workflow failed, the error is rethrown (with stack trace) unless
|
|
110
|
+
* `throwOnError: false` is set, in which case the error object is
|
|
111
|
+
* returned directly.
|
|
112
|
+
*
|
|
113
|
+
* @template T - The workflow's return type.
|
|
96
114
|
*/
|
|
97
115
|
result<T>(config?: {
|
|
98
116
|
state?: boolean;
|
|
@@ -3,28 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WorkflowHandleService = void 0;
|
|
4
4
|
const exporter_1 = require("./exporter");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* workflow.
|
|
8
|
-
* querying the state of the workflow. It is instanced/accessed via the
|
|
9
|
-
* Durable.Client class.
|
|
6
|
+
* Handle to a running or completed workflow execution. Returned by
|
|
7
|
+
* `client.workflow.start()` and `client.workflow.getHandle()`.
|
|
10
8
|
*
|
|
11
9
|
* @example
|
|
12
10
|
* ```typescript
|
|
13
|
-
* import { Client } from '@hotmeshio/hotmesh';
|
|
14
|
-
* import { Client as Postgres } from 'pg';
|
|
15
|
-
*
|
|
16
|
-
* const client = new Client({ connection: {
|
|
17
|
-
* class: Postgres,
|
|
18
|
-
* options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
|
|
19
|
-
* }});
|
|
20
|
-
*
|
|
21
11
|
* const handle = await client.workflow.start({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
12
|
+
* args: ['order-123'],
|
|
13
|
+
* taskQueue: 'orders',
|
|
14
|
+
* workflowName: 'orderWorkflow',
|
|
15
|
+
* workflowId: Durable.guid(),
|
|
24
16
|
* });
|
|
25
17
|
*
|
|
26
|
-
* //
|
|
27
|
-
* await handle.
|
|
18
|
+
* // Await the final result
|
|
19
|
+
* const result = await handle.result();
|
|
20
|
+
*
|
|
21
|
+
* // Or interact while running
|
|
22
|
+
* await handle.signal('approval', { approved: true });
|
|
23
|
+
* await handle.cancel();
|
|
28
24
|
* ```
|
|
29
25
|
*/
|
|
30
26
|
class WorkflowHandleService {
|
|
@@ -38,13 +34,14 @@ class WorkflowHandleService {
|
|
|
38
34
|
this.exporter = new exporter_1.ExporterService(this.hotMesh.appId, this.hotMesh.engine.store, this.hotMesh.engine.logger);
|
|
39
35
|
}
|
|
40
36
|
/**
|
|
41
|
-
* Exports the workflow state
|
|
37
|
+
* Exports the full workflow state (job hash, metadata, activity
|
|
38
|
+
* results) as a JSON object.
|
|
42
39
|
*/
|
|
43
40
|
async export(options) {
|
|
44
41
|
return this.exporter.export(this.workflowId, options);
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
|
-
* Exports the workflow as
|
|
44
|
+
* Exports the workflow as an execution event history.
|
|
48
45
|
*
|
|
49
46
|
* **Sparse mode** (default): transforms the main workflow's timeline
|
|
50
47
|
* into a flat event list with workflow lifecycle, activity, child workflow,
|
|
@@ -57,10 +54,12 @@ class WorkflowHandleService {
|
|
|
57
54
|
return this.exporter.exportExecution(this.workflowId, this.workflowTopic, options);
|
|
58
55
|
}
|
|
59
56
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
57
|
+
* Delivers a named signal to the workflow. If the workflow is paused
|
|
58
|
+
* on `Durable.workflow.condition(signalId)`, it resumes with the
|
|
59
|
+
* provided data.
|
|
60
|
+
*
|
|
61
|
+
* @param signalId - Matches the `signalId` passed to `condition()`.
|
|
62
|
+
* @param data - Payload delivered to the waiting workflow.
|
|
64
63
|
*/
|
|
65
64
|
async signal(signalId, data) {
|
|
66
65
|
await this.hotMesh.signal(`${this.hotMesh.appId}.wfs.signal`, {
|
|
@@ -69,10 +68,12 @@ class WorkflowHandleService {
|
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
/**
|
|
72
|
-
* Returns the
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
71
|
+
* Returns the current workflow state. For a completed workflow this
|
|
72
|
+
* is the final output; for a running workflow it reflects the latest
|
|
73
|
+
* persisted state (may change as activities complete).
|
|
74
|
+
*
|
|
75
|
+
* @param metadata - If `true`, returns the full job envelope including
|
|
76
|
+
* internal metadata alongside the data.
|
|
76
77
|
*/
|
|
77
78
|
async state(metadata = false) {
|
|
78
79
|
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
@@ -82,35 +83,54 @@ class WorkflowHandleService {
|
|
|
82
83
|
return metadata ? state : state.data;
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
|
-
* Returns
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* to
|
|
86
|
+
* Returns key-value pairs previously written via
|
|
87
|
+
* `Durable.workflow.search()` or `Durable.workflow.enrich()`.
|
|
88
|
+
*
|
|
89
|
+
* @param fields - The field names to retrieve.
|
|
89
90
|
*/
|
|
90
91
|
async queryState(fields) {
|
|
91
92
|
return await this.hotMesh.getQueryState(this.workflowId, fields);
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
94
|
-
* Returns the
|
|
95
|
-
*
|
|
96
|
-
* 0 is complete and a negative value represents that the flow was
|
|
97
|
-
* interrupted.
|
|
95
|
+
* Returns the workflow's numeric status code: `0` = completed,
|
|
96
|
+
* positive = still running, negative = interrupted/errored.
|
|
98
97
|
*/
|
|
99
98
|
async status() {
|
|
100
99
|
return await this.hotMesh.getStatus(this.workflowId);
|
|
101
100
|
}
|
|
102
101
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
102
|
+
* Immediately terminates the workflow. The job is marked as interrupted,
|
|
103
|
+
* subscribers are notified, and the job hash is expired. Unlike
|
|
104
|
+
* {@link cancel}, this does **not** give the workflow a chance to
|
|
105
|
+
* run cleanup code.
|
|
105
106
|
*/
|
|
106
|
-
async
|
|
107
|
+
async terminate(options) {
|
|
107
108
|
return await this.hotMesh.interrupt(`${this.hotMesh.appId}.execute`, this.workflowId, options);
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
111
|
+
* Requests cooperative cancellation of the workflow. Unlike
|
|
112
|
+
* `terminate()` (which terminates immediately), `cancel()` sets
|
|
113
|
+
* a durable flag that the workflow detects at its next durable
|
|
114
|
+
* operation (`sleep`, `proxyActivities`, `executeChild`, etc.).
|
|
115
|
+
* The workflow receives a `CancelledFailure` error that it can
|
|
116
|
+
* catch to perform cleanup before exiting.
|
|
117
|
+
*
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const handle = await client.workflow.start({ ... });
|
|
120
|
+
* await handle.cancel();
|
|
121
|
+
* // Workflow will throw CancelledFailure at its next durable operation
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
async cancel() {
|
|
125
|
+
await this.hotMesh.cancel(this.workflowId);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Blocks until the workflow completes and returns the result. If the
|
|
129
|
+
* workflow failed, the error is rethrown (with stack trace) unless
|
|
130
|
+
* `throwOnError: false` is set, in which case the error object is
|
|
131
|
+
* returned directly.
|
|
132
|
+
*
|
|
133
|
+
* @template T - The workflow's return type.
|
|
114
134
|
*/
|
|
115
135
|
async result(config) {
|
|
116
136
|
const topic = `${this.hotMesh.appId}.executed.${this.workflowId}`;
|