@hotmeshio/hotmesh 0.3.28 → 0.3.29
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/build/modules/key.js +1 -1
- package/build/modules/utils.js +1 -1
- package/build/package.json +1 -1
- package/build/services/activities/activity.js +1 -1
- package/build/services/activities/await.js +1 -1
- package/build/services/activities/cycle.js +1 -1
- package/build/services/activities/hook.js +1 -1
- package/build/services/activities/index.js +1 -1
- package/build/services/activities/interrupt.js +1 -1
- package/build/services/activities/signal.js +1 -1
- package/build/services/activities/trigger.js +1 -1
- package/build/services/activities/worker.js +1 -1
- package/build/services/collator/index.js +1 -1
- package/build/services/compiler/deployer.js +1 -1
- package/build/services/compiler/index.js +1 -1
- package/build/services/compiler/validator.js +1 -1
- package/build/services/engine/index.js +1 -1
- package/build/services/exporter/index.js +1 -1
- package/build/services/hotmesh/index.js +3 -0
- package/build/services/mapper/index.js +1 -1
- package/build/services/meshdata/index.d.ts +10 -10
- package/build/services/meshflow/client.js +1 -0
- package/build/services/meshflow/exporter.js +1 -1
- package/build/services/meshflow/workflow/all.d.ts +1 -0
- package/build/services/meshflow/workflow/all.js +8 -0
- package/build/services/meshflow/workflow/common.d.ts +18 -0
- package/build/services/meshflow/workflow/common.js +45 -0
- package/build/services/meshflow/workflow/context.d.ts +2 -0
- package/build/services/meshflow/workflow/context.js +41 -0
- package/build/services/meshflow/workflow/didRun.d.ts +1 -0
- package/build/services/meshflow/workflow/didRun.js +16 -0
- package/build/services/meshflow/workflow/emit.d.ts +4 -0
- package/build/services/meshflow/workflow/emit.js +22 -0
- package/build/services/meshflow/workflow/enrich.d.ts +2 -0
- package/build/services/meshflow/workflow/enrich.js +10 -0
- package/build/services/meshflow/workflow/execChild.d.ts +4 -0
- package/build/services/meshflow/workflow/execChild.js +84 -0
- package/build/services/meshflow/workflow/hook.d.ts +2 -0
- package/build/services/meshflow/workflow/hook.js +33 -0
- package/build/services/meshflow/workflow/index.d.ts +39 -0
- package/build/services/meshflow/workflow/index.js +52 -0
- package/build/services/meshflow/workflow/interrupt.d.ts +2 -0
- package/build/services/meshflow/workflow/interrupt.js +17 -0
- package/build/services/meshflow/workflow/isSideEffectAllowed.d.ts +2 -0
- package/build/services/meshflow/workflow/isSideEffectAllowed.js +25 -0
- package/build/services/meshflow/workflow/proxyActivities.d.ts +6 -0
- package/build/services/meshflow/workflow/proxyActivities.js +82 -0
- package/build/services/meshflow/workflow/random.d.ts +1 -0
- package/build/services/meshflow/workflow/random.js +11 -0
- package/build/services/meshflow/workflow/searchMethods.d.ts +2 -0
- package/build/services/meshflow/workflow/searchMethods.js +21 -0
- package/build/services/meshflow/workflow/signal.d.ts +1 -0
- package/build/services/meshflow/workflow/signal.js +22 -0
- package/build/services/meshflow/workflow/sleepFor.d.ts +1 -0
- package/build/services/meshflow/workflow/sleepFor.js +28 -0
- package/build/services/meshflow/workflow/trace.d.ts +4 -0
- package/build/services/meshflow/workflow/trace.js +23 -0
- package/build/services/meshflow/workflow/waitFor.d.ts +1 -0
- package/build/services/meshflow/workflow/waitFor.js +28 -0
- package/build/services/meshos/index.d.ts +8 -5
- package/build/services/meshos/index.js +31 -10
- package/build/services/pipe/functions/array.js +1 -1
- package/build/services/pipe/functions/bitwise.js +1 -1
- package/build/services/pipe/functions/conditional.js +1 -1
- package/build/services/pipe/functions/cron.js +1 -1
- package/build/services/pipe/functions/date.js +1 -1
- package/build/services/pipe/functions/index.js +1 -1
- package/build/services/pipe/functions/json.js +1 -1
- package/build/services/pipe/functions/logical.js +1 -1
- package/build/services/pipe/functions/math.js +1 -1
- package/build/services/pipe/functions/number.js +1 -1
- package/build/services/pipe/functions/object.js +1 -1
- package/build/services/pipe/functions/string.js +1 -1
- package/build/services/pipe/functions/symbol.js +1 -1
- package/build/services/pipe/functions/unary.js +1 -1
- package/build/services/pipe/index.js +1 -1
- package/build/services/quorum/index.js +1 -1
- package/build/services/reporter/index.js +1 -1
- package/build/services/router/index.js +1 -1
- package/build/services/search/providers/postgres/postgres.js +1 -1
- package/build/services/search/providers/redis/ioredis.js +1 -1
- package/build/services/search/providers/redis/redis.js +1 -1
- package/build/services/serializer/index.js +1 -1
- package/build/services/store/providers/postgres/kvsql.js +1 -1
- package/build/services/store/providers/postgres/kvtables.js +1 -1
- package/build/services/store/providers/postgres/kvtransaction.js +1 -1
- package/build/services/store/providers/postgres/kvtypes/hash.js +1 -1
- package/build/services/store/providers/postgres/kvtypes/list.js +1 -1
- package/build/services/store/providers/postgres/kvtypes/string.js +1 -1
- package/build/services/store/providers/postgres/kvtypes/zset.js +1 -1
- package/build/services/store/providers/postgres/postgres.js +1 -1
- package/build/services/store/providers/redis/_base.js +1 -1
- package/build/services/store/providers/redis/ioredis.js +1 -1
- package/build/services/store/providers/redis/redis.js +1 -1
- package/build/services/store/providers/store-initializable.js +1 -1
- package/build/services/stream/providers/nats/nats.js +1 -1
- package/build/services/stream/providers/postgres/kvtables.js +1 -1
- package/build/services/stream/providers/postgres/postgres.js +1 -1
- package/build/services/stream/providers/redis/ioredis.js +1 -1
- package/build/services/stream/providers/redis/redis.js +1 -1
- package/build/services/stream/providers/stream-initializable.js +1 -1
- package/build/services/sub/providers/nats/nats.js +1 -1
- package/build/services/sub/providers/postgres/postgres.js +1 -1
- package/build/services/sub/providers/redis/ioredis.js +1 -1
- package/build/services/sub/providers/redis/redis.js +1 -1
- package/build/services/task/index.js +1 -1
- package/build/services/telemetry/index.js +1 -1
- package/build/services/worker/index.js +1 -1
- package/build/types/manifest.d.ts +2 -0
- package/build/types/provider.d.ts +2 -0
- package/package.json +1 -1
- package/types/manifest.ts +12 -2
- package/types/provider.ts +14 -0
- package/build/services/meshflow/workflow.d.ts +0 -35
- package/build/services/meshflow/workflow.js +0 -403
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emit = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
6
|
+
async function emit(events, config = { once: true }) {
|
|
7
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
8
|
+
const workflowTopic = store.get('workflowTopic');
|
|
9
|
+
const connection = store.get('connection');
|
|
10
|
+
const namespace = store.get('namespace');
|
|
11
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
12
|
+
connection,
|
|
13
|
+
namespace,
|
|
14
|
+
});
|
|
15
|
+
if (!config.once || await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'emit')) {
|
|
16
|
+
for (const [topic, message] of Object.entries(events)) {
|
|
17
|
+
await hotMeshClient.quorum.pub({ topic, message });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
exports.emit = emit;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enrich = void 0;
|
|
4
|
+
const searchMethods_1 = require("./searchMethods");
|
|
5
|
+
async function enrich(fields) {
|
|
6
|
+
const searchSession = await (0, searchMethods_1.search)();
|
|
7
|
+
await searchSession.set(fields);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
exports.enrich = enrich;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startChild = exports.executeChild = exports.execChild = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const didRun_1 = require("./didRun");
|
|
7
|
+
function getChildInterruptPayload(context, options, execIndex) {
|
|
8
|
+
const { workflowId, originJobId, workflowDimension, expire } = context;
|
|
9
|
+
let childJobId;
|
|
10
|
+
if (options.workflowId) {
|
|
11
|
+
childJobId = options.workflowId;
|
|
12
|
+
}
|
|
13
|
+
else if (options.entity) {
|
|
14
|
+
childJobId = `${options.entity}-${(0, common_1.guid)()}-${workflowDimension}-${execIndex}`;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
childJobId = `-${options.workflowName}-${(0, common_1.guid)()}-${workflowDimension}-${execIndex}`;
|
|
18
|
+
}
|
|
19
|
+
const parentWorkflowId = workflowId;
|
|
20
|
+
const taskQueueName = options.taskQueue ?? options.entity;
|
|
21
|
+
const workflowName = options.entity ?? options.workflowName;
|
|
22
|
+
const workflowTopic = `${taskQueueName}-${workflowName}`;
|
|
23
|
+
return {
|
|
24
|
+
arguments: [...(options.args || [])],
|
|
25
|
+
await: options?.await ?? true,
|
|
26
|
+
backoffCoefficient: options?.config?.backoffCoefficient ?? common_1.HMSH_MESHFLOW_EXP_BACKOFF,
|
|
27
|
+
index: execIndex,
|
|
28
|
+
maximumAttempts: options?.config?.maximumAttempts ?? common_1.HMSH_MESHFLOW_MAX_ATTEMPTS,
|
|
29
|
+
maximumInterval: (0, common_1.s)(options?.config?.maximumInterval ?? common_1.HMSH_MESHFLOW_MAX_INTERVAL),
|
|
30
|
+
originJobId: originJobId ?? workflowId,
|
|
31
|
+
expire: options.expire ?? expire,
|
|
32
|
+
persistent: options.persistent,
|
|
33
|
+
signalIn: options.signalIn,
|
|
34
|
+
parentWorkflowId,
|
|
35
|
+
workflowDimension: workflowDimension,
|
|
36
|
+
workflowId: childJobId,
|
|
37
|
+
workflowTopic,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async function execChild(options) {
|
|
41
|
+
const isStartChild = options.await === false;
|
|
42
|
+
const prefix = isStartChild ? 'start' : 'child';
|
|
43
|
+
const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)(prefix);
|
|
44
|
+
const context = (0, context_1.getContext)();
|
|
45
|
+
const { canRetry, interruptionRegistry } = context;
|
|
46
|
+
if (didRunAlready) {
|
|
47
|
+
if (result?.$error && (!result.$error.is_stream_error || !canRetry)) {
|
|
48
|
+
if (options?.config?.throwOnError !== false) {
|
|
49
|
+
const code = result.$error.code;
|
|
50
|
+
const message = result.$error.message;
|
|
51
|
+
const stack = result.$error.stack;
|
|
52
|
+
if (code === common_1.HMSH_CODE_MESHFLOW_FATAL) {
|
|
53
|
+
throw new common_1.MeshFlowFatalError(message, stack);
|
|
54
|
+
}
|
|
55
|
+
else if (code === common_1.HMSH_CODE_MESHFLOW_MAXED) {
|
|
56
|
+
throw new common_1.MeshFlowMaxedError(message, stack);
|
|
57
|
+
}
|
|
58
|
+
else if (code === common_1.HMSH_CODE_MESHFLOW_TIMEOUT) {
|
|
59
|
+
throw new common_1.MeshFlowTimeoutError(message, stack);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new common_1.MeshFlowRetryError(message, stack);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result.$error;
|
|
66
|
+
}
|
|
67
|
+
else if (!result?.$error) {
|
|
68
|
+
return result.data;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const interruptionMessage = getChildInterruptPayload(context, options, execIndex);
|
|
72
|
+
interruptionRegistry.push({
|
|
73
|
+
code: common_1.HMSH_CODE_MESHFLOW_CHILD,
|
|
74
|
+
...interruptionMessage,
|
|
75
|
+
});
|
|
76
|
+
await (0, common_1.sleepImmediate)();
|
|
77
|
+
throw new common_1.MeshFlowChildError(interruptionMessage);
|
|
78
|
+
}
|
|
79
|
+
exports.execChild = execChild;
|
|
80
|
+
exports.executeChild = execChild;
|
|
81
|
+
async function startChild(options) {
|
|
82
|
+
return execChild({ ...options, await: false });
|
|
83
|
+
}
|
|
84
|
+
exports.startChild = startChild;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hook = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
7
|
+
async function hook(options) {
|
|
8
|
+
const { workflowId, connection, namespace, workflowTopic } = (0, context_1.getContext)();
|
|
9
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
10
|
+
connection,
|
|
11
|
+
namespace,
|
|
12
|
+
});
|
|
13
|
+
if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'hook')) {
|
|
14
|
+
const targetWorkflowId = options.workflowId ?? workflowId;
|
|
15
|
+
let targetTopic;
|
|
16
|
+
if (options.entity || (options.taskQueue && options.workflowName)) {
|
|
17
|
+
targetTopic = `${options.taskQueue ?? options.entity}-${options.entity ?? options.workflowName}`;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
targetTopic = workflowTopic;
|
|
21
|
+
}
|
|
22
|
+
const payload = {
|
|
23
|
+
arguments: [...options.args],
|
|
24
|
+
id: targetWorkflowId,
|
|
25
|
+
workflowTopic: targetTopic,
|
|
26
|
+
backoffCoefficient: options.config?.backoffCoefficient || common_1.HMSH_MESHFLOW_EXP_BACKOFF,
|
|
27
|
+
maximumAttempts: options.config?.maximumAttempts || common_1.HMSH_MESHFLOW_MAX_ATTEMPTS,
|
|
28
|
+
maximumInterval: (0, common_1.s)(options?.config?.maximumInterval ?? common_1.HMSH_MESHFLOW_MAX_INTERVAL),
|
|
29
|
+
};
|
|
30
|
+
return await hotMeshClient.hook(`${namespace}.flow.signal`, payload, common_1.StreamStatus.PENDING, 202);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.hook = hook;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getContext } from './context';
|
|
2
|
+
import { didRun } from './didRun';
|
|
3
|
+
import { isSideEffectAllowed } from './isSideEffectAllowed';
|
|
4
|
+
import { trace } from './trace';
|
|
5
|
+
import { enrich } from './enrich';
|
|
6
|
+
import { emit } from './emit';
|
|
7
|
+
import { execChild, startChild } from './execChild';
|
|
8
|
+
import { proxyActivities } from './proxyActivities';
|
|
9
|
+
import { search } from './searchMethods';
|
|
10
|
+
import { random } from './random';
|
|
11
|
+
import { signal } from './signal';
|
|
12
|
+
import { hook } from './hook';
|
|
13
|
+
import { interrupt } from './interrupt';
|
|
14
|
+
import { all } from './all';
|
|
15
|
+
import { sleepFor } from './sleepFor';
|
|
16
|
+
import { waitFor } from './waitFor';
|
|
17
|
+
import { HotMesh } from './common';
|
|
18
|
+
export declare class WorkflowService {
|
|
19
|
+
private constructor();
|
|
20
|
+
static getContext: typeof getContext;
|
|
21
|
+
static didRun: typeof didRun;
|
|
22
|
+
static isSideEffectAllowed: typeof isSideEffectAllowed;
|
|
23
|
+
static trace: typeof trace;
|
|
24
|
+
static enrich: typeof enrich;
|
|
25
|
+
static emit: typeof emit;
|
|
26
|
+
static execChild: typeof execChild;
|
|
27
|
+
static executeChild: typeof execChild;
|
|
28
|
+
static startChild: typeof startChild;
|
|
29
|
+
static proxyActivities: typeof proxyActivities;
|
|
30
|
+
static search: typeof search;
|
|
31
|
+
static random: typeof random;
|
|
32
|
+
static signal: typeof signal;
|
|
33
|
+
static hook: typeof hook;
|
|
34
|
+
static interrupt: typeof interrupt;
|
|
35
|
+
static all: typeof all;
|
|
36
|
+
static sleepFor: typeof sleepFor;
|
|
37
|
+
static waitFor: typeof waitFor;
|
|
38
|
+
static getHotMesh(): Promise<HotMesh>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowService = void 0;
|
|
4
|
+
const context_1 = require("./context");
|
|
5
|
+
const didRun_1 = require("./didRun");
|
|
6
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
7
|
+
const trace_1 = require("./trace");
|
|
8
|
+
const enrich_1 = require("./enrich");
|
|
9
|
+
const emit_1 = require("./emit");
|
|
10
|
+
const execChild_1 = require("./execChild");
|
|
11
|
+
const proxyActivities_1 = require("./proxyActivities");
|
|
12
|
+
const searchMethods_1 = require("./searchMethods");
|
|
13
|
+
const random_1 = require("./random");
|
|
14
|
+
const signal_1 = require("./signal");
|
|
15
|
+
const hook_1 = require("./hook");
|
|
16
|
+
const interrupt_1 = require("./interrupt");
|
|
17
|
+
const all_1 = require("./all");
|
|
18
|
+
const sleepFor_1 = require("./sleepFor");
|
|
19
|
+
const waitFor_1 = require("./waitFor");
|
|
20
|
+
const common_1 = require("./common");
|
|
21
|
+
class WorkflowService {
|
|
22
|
+
constructor() { }
|
|
23
|
+
static async getHotMesh() {
|
|
24
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
25
|
+
const workflowTopic = store.get('workflowTopic');
|
|
26
|
+
const connection = store.get('connection');
|
|
27
|
+
const namespace = store.get('namespace');
|
|
28
|
+
return await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
29
|
+
connection,
|
|
30
|
+
namespace,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
WorkflowService.getContext = context_1.getContext;
|
|
35
|
+
WorkflowService.didRun = didRun_1.didRun;
|
|
36
|
+
WorkflowService.isSideEffectAllowed = isSideEffectAllowed_1.isSideEffectAllowed;
|
|
37
|
+
WorkflowService.trace = trace_1.trace;
|
|
38
|
+
WorkflowService.enrich = enrich_1.enrich;
|
|
39
|
+
WorkflowService.emit = emit_1.emit;
|
|
40
|
+
WorkflowService.execChild = execChild_1.execChild;
|
|
41
|
+
WorkflowService.executeChild = execChild_1.executeChild;
|
|
42
|
+
WorkflowService.startChild = execChild_1.startChild;
|
|
43
|
+
WorkflowService.proxyActivities = proxyActivities_1.proxyActivities;
|
|
44
|
+
WorkflowService.search = searchMethods_1.search;
|
|
45
|
+
WorkflowService.random = random_1.random;
|
|
46
|
+
WorkflowService.signal = signal_1.signal;
|
|
47
|
+
WorkflowService.hook = hook_1.hook;
|
|
48
|
+
WorkflowService.interrupt = interrupt_1.interrupt;
|
|
49
|
+
WorkflowService.all = all_1.all;
|
|
50
|
+
WorkflowService.sleepFor = sleepFor_1.sleepFor;
|
|
51
|
+
WorkflowService.waitFor = waitFor_1.waitFor;
|
|
52
|
+
exports.WorkflowService = WorkflowService;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interrupt = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
7
|
+
async function interrupt(jobId, options = {}) {
|
|
8
|
+
const { workflowTopic, connection, namespace } = (0, context_1.getContext)();
|
|
9
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
10
|
+
connection,
|
|
11
|
+
namespace,
|
|
12
|
+
});
|
|
13
|
+
if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'interrupt')) {
|
|
14
|
+
return await hotMeshClient.interrupt(`${hotMeshClient.appId}.execute`, jobId, options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.interrupt = interrupt;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSideEffectAllowed = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
async function isSideEffectAllowed(hotMeshClient, prefix) {
|
|
6
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
7
|
+
const workflowId = store.get('workflowId');
|
|
8
|
+
const workflowDimension = store.get('workflowDimension') ?? '';
|
|
9
|
+
const COUNTER = store.get('counter');
|
|
10
|
+
const execIndex = COUNTER.counter = COUNTER.counter + 1;
|
|
11
|
+
const sessionId = `-${prefix}${workflowDimension}-${execIndex}-`;
|
|
12
|
+
const replay = store.get('replay');
|
|
13
|
+
if (sessionId in replay) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const keyParams = {
|
|
17
|
+
appId: hotMeshClient.appId,
|
|
18
|
+
jobId: workflowId,
|
|
19
|
+
};
|
|
20
|
+
const workflowGuid = common_1.KeyService.mintKey(hotMeshClient.namespace, common_1.KeyType.JOB_STATE, keyParams);
|
|
21
|
+
const searchClient = hotMeshClient.engine.search;
|
|
22
|
+
const guidValue = await searchClient.incrementFieldByFloat(workflowGuid, sessionId, 1);
|
|
23
|
+
return guidValue === 1;
|
|
24
|
+
}
|
|
25
|
+
exports.isSideEffectAllowed = isSideEffectAllowed;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ActivityConfig, ProxyType, MeshFlowProxyErrorType } from './common';
|
|
2
|
+
import { getContext } from './context';
|
|
3
|
+
declare function getProxyInterruptPayload(context: ReturnType<typeof getContext>, activityName: string, execIndex: number, args: any[], options?: ActivityConfig): MeshFlowProxyErrorType;
|
|
4
|
+
declare function wrapActivity<T>(activityName: string, options?: ActivityConfig): T;
|
|
5
|
+
export declare function proxyActivities<ACT>(options?: ActivityConfig): ProxyType<ACT>;
|
|
6
|
+
export { wrapActivity, getProxyInterruptPayload };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProxyInterruptPayload = exports.wrapActivity = exports.proxyActivities = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const didRun_1 = require("./didRun");
|
|
7
|
+
function getProxyInterruptPayload(context, activityName, execIndex, args, options) {
|
|
8
|
+
const { workflowDimension, workflowId, originJobId, workflowTopic, expire, } = context;
|
|
9
|
+
const activityTopic = `${workflowTopic}-activity`;
|
|
10
|
+
const activityJobId = `-${workflowId}-$${activityName}${workflowDimension}-${execIndex}`;
|
|
11
|
+
let maximumInterval;
|
|
12
|
+
if (options?.retryPolicy?.maximumInterval) {
|
|
13
|
+
maximumInterval = (0, common_1.s)(options.retryPolicy.maximumInterval);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
arguments: args,
|
|
17
|
+
workflowDimension,
|
|
18
|
+
index: execIndex,
|
|
19
|
+
originJobId: originJobId || workflowId,
|
|
20
|
+
parentWorkflowId: workflowId,
|
|
21
|
+
workflowId: activityJobId,
|
|
22
|
+
workflowTopic: activityTopic,
|
|
23
|
+
activityName,
|
|
24
|
+
expire: options?.expire ?? expire,
|
|
25
|
+
backoffCoefficient: options?.retryPolicy?.backoffCoefficient ?? undefined,
|
|
26
|
+
maximumAttempts: options?.retryPolicy?.maximumAttempts ?? undefined,
|
|
27
|
+
maximumInterval: maximumInterval ?? undefined,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.getProxyInterruptPayload = getProxyInterruptPayload;
|
|
31
|
+
function wrapActivity(activityName, options) {
|
|
32
|
+
return (async function (...args) {
|
|
33
|
+
const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('proxy');
|
|
34
|
+
if (didRunAlready) {
|
|
35
|
+
if (result?.$error) {
|
|
36
|
+
if (options?.retryPolicy?.throwOnError !== false) {
|
|
37
|
+
const code = result.$error.code;
|
|
38
|
+
const message = result.$error.message;
|
|
39
|
+
const stack = result.$error.stack;
|
|
40
|
+
if (code === common_1.HMSH_CODE_MESHFLOW_FATAL) {
|
|
41
|
+
throw new common_1.MeshFlowFatalError(message, stack);
|
|
42
|
+
}
|
|
43
|
+
else if (code === common_1.HMSH_CODE_MESHFLOW_MAXED) {
|
|
44
|
+
throw new common_1.MeshFlowMaxedError(message, stack);
|
|
45
|
+
}
|
|
46
|
+
else if (code === common_1.HMSH_CODE_MESHFLOW_TIMEOUT) {
|
|
47
|
+
throw new common_1.MeshFlowTimeoutError(message, stack);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result.$error;
|
|
53
|
+
}
|
|
54
|
+
return result.data;
|
|
55
|
+
}
|
|
56
|
+
const context = (0, context_1.getContext)();
|
|
57
|
+
const { interruptionRegistry } = context;
|
|
58
|
+
const interruptionMessage = getProxyInterruptPayload(context, activityName, execIndex, args, options);
|
|
59
|
+
interruptionRegistry.push({
|
|
60
|
+
code: common_1.HMSH_CODE_MESHFLOW_PROXY,
|
|
61
|
+
...interruptionMessage,
|
|
62
|
+
});
|
|
63
|
+
await (0, common_1.sleepImmediate)();
|
|
64
|
+
throw new common_1.MeshFlowProxyError(interruptionMessage);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
exports.wrapActivity = wrapActivity;
|
|
68
|
+
function proxyActivities(options) {
|
|
69
|
+
if (options?.activities) {
|
|
70
|
+
common_1.WorkerService.registerActivities(options.activities);
|
|
71
|
+
}
|
|
72
|
+
const proxy = {};
|
|
73
|
+
const keys = Object.keys(common_1.WorkerService.activityRegistry);
|
|
74
|
+
if (keys.length) {
|
|
75
|
+
keys.forEach((key) => {
|
|
76
|
+
const activityFunction = common_1.WorkerService.activityRegistry[key];
|
|
77
|
+
proxy[key] = wrapActivity(key, options);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return proxy;
|
|
81
|
+
}
|
|
82
|
+
exports.proxyActivities = proxyActivities;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function random(): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.random = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
function random() {
|
|
6
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
7
|
+
const COUNTER = store.get('counter');
|
|
8
|
+
const seed = COUNTER.counter = COUNTER.counter + 1;
|
|
9
|
+
return (0, common_1.deterministicRandom)(seed);
|
|
10
|
+
}
|
|
11
|
+
exports.random = random;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.search = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
async function search() {
|
|
6
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
7
|
+
const workflowId = store.get('workflowId');
|
|
8
|
+
const workflowDimension = store.get('workflowDimension') ?? '';
|
|
9
|
+
const workflowTopic = store.get('workflowTopic');
|
|
10
|
+
const connection = store.get('connection');
|
|
11
|
+
const namespace = store.get('namespace');
|
|
12
|
+
const COUNTER = store.get('counter');
|
|
13
|
+
const execIndex = COUNTER.counter = COUNTER.counter + 1;
|
|
14
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
15
|
+
connection,
|
|
16
|
+
namespace,
|
|
17
|
+
});
|
|
18
|
+
const searchSessionId = `-search${workflowDimension}-${execIndex}`;
|
|
19
|
+
return new common_1.Search(workflowId, hotMeshClient, searchSessionId);
|
|
20
|
+
}
|
|
21
|
+
exports.search = search;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function signal(signalId: string, data: Record<any, any>): Promise<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signal = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
6
|
+
async function signal(signalId, data) {
|
|
7
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
8
|
+
const workflowTopic = store.get('workflowTopic');
|
|
9
|
+
const connection = store.get('connection');
|
|
10
|
+
const namespace = store.get('namespace');
|
|
11
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
12
|
+
connection,
|
|
13
|
+
namespace,
|
|
14
|
+
});
|
|
15
|
+
if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'signal')) {
|
|
16
|
+
return await hotMeshClient.hook(`${namespace}.wfs.signal`, {
|
|
17
|
+
id: signalId,
|
|
18
|
+
data,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.signal = signal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleepFor(duration: string): Promise<number>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleepFor = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const didRun_1 = require("./didRun");
|
|
6
|
+
async function sleepFor(duration) {
|
|
7
|
+
const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('sleep');
|
|
8
|
+
if (didRunAlready) {
|
|
9
|
+
return result.duration;
|
|
10
|
+
}
|
|
11
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
12
|
+
const interruptionRegistry = store.get('interruptionRegistry');
|
|
13
|
+
const workflowId = store.get('workflowId');
|
|
14
|
+
const workflowDimension = store.get('workflowDimension') ?? '';
|
|
15
|
+
const interruptionMessage = {
|
|
16
|
+
workflowId,
|
|
17
|
+
duration: (0, common_1.s)(duration),
|
|
18
|
+
index: execIndex,
|
|
19
|
+
workflowDimension,
|
|
20
|
+
};
|
|
21
|
+
interruptionRegistry.push({
|
|
22
|
+
code: common_1.HMSH_CODE_MESHFLOW_SLEEP,
|
|
23
|
+
...interruptionMessage,
|
|
24
|
+
});
|
|
25
|
+
await (0, common_1.sleepImmediate)();
|
|
26
|
+
throw new common_1.MeshFlowSleepError(interruptionMessage);
|
|
27
|
+
}
|
|
28
|
+
exports.sleepFor = sleepFor;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trace = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
7
|
+
async function trace(attributes, config = { once: true }) {
|
|
8
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
9
|
+
const workflowTopic = store.get('workflowTopic');
|
|
10
|
+
const connection = store.get('connection');
|
|
11
|
+
const namespace = store.get('namespace');
|
|
12
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
13
|
+
connection,
|
|
14
|
+
namespace,
|
|
15
|
+
});
|
|
16
|
+
const { raw, COUNTER } = (0, context_1.getContext)();
|
|
17
|
+
const { trc: traceId, spn: spanId, aid: activityId } = raw.metadata;
|
|
18
|
+
if (!config.once || await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'trace')) {
|
|
19
|
+
return await common_1.TelemetryService.traceActivity(namespace, attributes, activityId, traceId, spanId, COUNTER.counter);
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
exports.trace = trace;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function waitFor<T>(signalId: string): Promise<T>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitFor = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const didRun_1 = require("./didRun");
|
|
6
|
+
async function waitFor(signalId) {
|
|
7
|
+
const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('wait');
|
|
8
|
+
if (didRunAlready) {
|
|
9
|
+
return result.data.data;
|
|
10
|
+
}
|
|
11
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
12
|
+
const interruptionRegistry = store.get('interruptionRegistry');
|
|
13
|
+
const workflowId = store.get('workflowId');
|
|
14
|
+
const workflowDimension = store.get('workflowDimension') ?? '';
|
|
15
|
+
const interruptionMessage = {
|
|
16
|
+
workflowId,
|
|
17
|
+
signalId,
|
|
18
|
+
index: execIndex,
|
|
19
|
+
workflowDimension,
|
|
20
|
+
};
|
|
21
|
+
interruptionRegistry.push({
|
|
22
|
+
code: common_1.HMSH_CODE_MESHFLOW_WAIT,
|
|
23
|
+
...interruptionMessage,
|
|
24
|
+
});
|
|
25
|
+
await (0, common_1.sleepImmediate)();
|
|
26
|
+
throw new common_1.MeshFlowWaitForError(interruptionMessage);
|
|
27
|
+
}
|
|
28
|
+
exports.waitFor = waitFor;
|
|
@@ -5,7 +5,9 @@ declare abstract class MeshOS {
|
|
|
5
5
|
meshData: MeshData;
|
|
6
6
|
connected: boolean;
|
|
7
7
|
namespace: string;
|
|
8
|
-
|
|
8
|
+
schema: Types.WorkflowSearchSchema;
|
|
9
|
+
entity: string;
|
|
10
|
+
taskQueue: string;
|
|
9
11
|
static databases: Record<string, Types.DB>;
|
|
10
12
|
static namespaces: Types.Namespaces;
|
|
11
13
|
static entities: Record<string, Types.Entity>;
|
|
@@ -13,13 +15,14 @@ declare abstract class MeshOS {
|
|
|
13
15
|
static profiles: Types.Profiles;
|
|
14
16
|
static classes: Record<string, typeof MeshOS>;
|
|
15
17
|
static logger: Types.ILogger;
|
|
16
|
-
constructor(providerConfig: ProviderConfig | ProvidersConfig, namespace: string,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
constructor(providerConfig: ProviderConfig | ProvidersConfig, namespace: string, entity?: string, taskQueue?: string, schema?: Types.WorkflowSearchSchema);
|
|
19
|
+
getEntity(): string;
|
|
20
|
+
getSearchOptions(): Types.WorkflowSearchOptions;
|
|
21
|
+
getTaskQueue(): string;
|
|
20
22
|
private initializeMeshData;
|
|
21
23
|
protected defaultTargetFn(): Promise<string>;
|
|
22
24
|
getNamespace(): string;
|
|
25
|
+
getSchema(): Types.WorkflowSearchSchema;
|
|
23
26
|
connect(): Promise<void>;
|
|
24
27
|
index(): Promise<void>;
|
|
25
28
|
static shutdown(): Promise<void>;
|