@hotmeshio/hotmesh 0.3.32 → 0.4.1
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 +128 -823
- package/build/index.d.ts +9 -9
- package/build/index.js +10 -10
- package/build/modules/enums.d.ts +23 -23
- package/build/modules/enums.js +26 -26
- package/build/modules/errors.d.ts +16 -16
- package/build/modules/errors.js +28 -28
- package/build/modules/key.js +190 -1
- package/build/modules/utils.js +374 -1
- package/build/package.json +22 -21
- package/build/services/activities/activity.js +549 -1
- package/build/services/activities/await.js +114 -1
- package/build/services/activities/cycle.js +112 -1
- package/build/services/activities/hook.js +168 -1
- package/build/services/activities/index.js +20 -1
- package/build/services/activities/interrupt.js +158 -1
- package/build/services/activities/signal.js +134 -1
- package/build/services/activities/trigger.js +246 -1
- package/build/services/activities/worker.js +106 -1
- package/build/services/collator/index.js +293 -1
- package/build/services/compiler/deployer.js +488 -1
- package/build/services/compiler/index.js +112 -1
- package/build/services/compiler/validator.js +147 -1
- package/build/services/engine/index.js +761 -1
- package/build/services/exporter/index.js +126 -1
- package/build/services/hotmesh/index.d.ts +160 -17
- package/build/services/hotmesh/index.js +160 -17
- package/build/services/mapper/index.js +81 -1
- package/build/services/{meshflow → memflow}/client.d.ts +3 -3
- package/build/services/{meshflow → memflow}/client.js +17 -16
- package/build/services/{meshflow → memflow}/connection.d.ts +2 -2
- package/build/services/{meshflow → memflow}/connection.js +1 -1
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/{meshflow → memflow}/exporter.d.ts +6 -6
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/{meshflow → memflow}/handle.d.ts +4 -4
- package/build/services/{meshflow → memflow}/handle.js +2 -2
- package/build/services/{meshflow → memflow}/index.d.ts +18 -13
- package/build/services/{meshflow → memflow}/index.js +26 -21
- package/build/services/{meshflow → memflow}/schemas/factory.d.ts +4 -4
- package/build/services/{meshflow → memflow}/schemas/factory.js +5 -5
- package/build/services/{meshflow → memflow}/search.d.ts +1 -1
- package/build/services/{meshflow → memflow}/search.js +4 -4
- package/build/services/{meshflow → memflow}/worker.d.ts +5 -5
- package/build/services/{meshflow → memflow}/worker.js +24 -24
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/{meshflow → memflow}/workflow/execChild.js +12 -12
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/{meshflow → memflow}/workflow/hook.js +19 -3
- package/build/services/{meshflow → memflow}/workflow/index.d.ts +7 -3
- package/build/services/{meshflow → memflow}/workflow/index.js +7 -3
- package/build/services/{meshflow → memflow}/workflow/proxyActivities.d.ts +2 -2
- package/build/services/{meshflow → memflow}/workflow/proxyActivities.js +8 -8
- package/build/services/{meshflow → memflow}/workflow/sleepFor.js +2 -2
- package/build/services/{meshflow → memflow}/workflow/waitFor.js +2 -2
- package/build/services/meshdata/index.d.ts +24 -24
- package/build/services/meshdata/index.js +40 -40
- package/build/services/pipe/functions/array.js +74 -1
- package/build/services/pipe/functions/bitwise.js +24 -1
- package/build/services/pipe/functions/conditional.js +36 -1
- package/build/services/pipe/functions/cron.js +40 -1
- package/build/services/pipe/functions/date.js +171 -1
- package/build/services/pipe/functions/index.js +30 -1
- package/build/services/pipe/functions/json.js +12 -1
- package/build/services/pipe/functions/logical.js +12 -1
- package/build/services/pipe/functions/math.js +184 -1
- package/build/services/pipe/functions/number.js +60 -1
- package/build/services/pipe/functions/object.js +81 -1
- package/build/services/pipe/functions/string.js +69 -1
- package/build/services/pipe/functions/symbol.js +33 -1
- package/build/services/pipe/functions/unary.js +18 -1
- package/build/services/pipe/index.js +242 -1
- package/build/services/quorum/index.js +263 -1
- package/build/services/reporter/index.js +348 -1
- package/build/services/router/config/index.d.ts +11 -0
- package/build/services/router/config/index.js +36 -0
- package/build/services/router/consumption/index.d.ts +34 -0
- package/build/services/router/consumption/index.js +395 -0
- package/build/services/router/error-handling/index.d.ts +8 -0
- package/build/services/router/error-handling/index.js +98 -0
- package/build/services/router/index.d.ts +13 -16
- package/build/services/router/index.js +121 -1
- package/build/services/router/lifecycle/index.d.ts +27 -0
- package/build/services/router/lifecycle/index.js +80 -0
- package/build/services/router/telemetry/index.d.ts +11 -0
- package/build/services/router/telemetry/index.js +32 -0
- package/build/services/router/throttling/index.d.ts +23 -0
- package/build/services/router/throttling/index.js +76 -0
- package/build/services/search/index.d.ts +2 -1
- package/build/services/search/providers/postgres/postgres.d.ts +2 -1
- package/build/services/search/providers/postgres/postgres.js +149 -1
- package/build/services/search/providers/redis/ioredis.d.ts +1 -0
- package/build/services/search/providers/redis/ioredis.js +121 -1
- package/build/services/search/providers/redis/redis.d.ts +1 -0
- package/build/services/search/providers/redis/redis.js +134 -1
- package/build/services/serializer/index.js +282 -1
- package/build/services/store/providers/postgres/kvsql.d.ts +1 -1
- package/build/services/store/providers/postgres/kvsql.js +198 -1
- package/build/services/store/providers/postgres/kvtables.js +441 -1
- package/build/services/store/providers/postgres/kvtransaction.js +248 -1
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +1 -1
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -1
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -1
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -1
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -1
- package/build/services/store/providers/postgres/postgres.js +1036 -1
- package/build/services/store/providers/redis/_base.js +980 -1
- package/build/services/store/providers/redis/ioredis.js +180 -1
- package/build/services/store/providers/redis/redis.js +199 -1
- package/build/services/store/providers/store-initializable.js +2 -1
- package/build/services/stream/index.d.ts +5 -0
- package/build/services/stream/providers/nats/nats.d.ts +1 -0
- package/build/services/stream/providers/nats/nats.js +225 -1
- package/build/services/stream/providers/postgres/kvtables.d.ts +1 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -1
- package/build/services/stream/providers/postgres/postgres.d.ts +19 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -1
- package/build/services/stream/providers/redis/ioredis.d.ts +1 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -1
- package/build/services/stream/providers/redis/redis.d.ts +1 -0
- package/build/services/stream/providers/redis/redis.js +305 -1
- package/build/services/stream/providers/stream-initializable.js +2 -1
- package/build/services/sub/providers/nats/nats.js +105 -1
- package/build/services/sub/providers/postgres/postgres.js +92 -1
- package/build/services/sub/providers/redis/ioredis.js +81 -1
- package/build/services/sub/providers/redis/redis.js +72 -1
- package/build/services/task/index.js +206 -1
- package/build/services/telemetry/index.js +306 -1
- package/build/services/worker/index.js +197 -1
- package/build/types/error.d.ts +5 -5
- package/build/types/exporter.d.ts +1 -1
- package/build/types/index.d.ts +3 -3
- package/build/types/manifest.d.ts +2 -2
- package/build/types/{meshflow.d.ts → memflow.d.ts} +15 -15
- package/build/types/meshdata.d.ts +3 -3
- package/build/types/postgres.d.ts +7 -0
- package/build/types/stream.d.ts +3 -0
- package/index.ts +11 -11
- package/package.json +22 -21
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/build/services/meshflow/exporter.js +0 -1
- package/build/services/meshflow/workflow/common.d.ts +0 -18
- package/build/services/meshflow/workflow/common.js +0 -45
- package/typedoc.json +0 -46
- package/types/activity.ts +0 -268
- package/types/app.ts +0 -20
- package/types/async.ts +0 -6
- package/types/cache.ts +0 -1
- package/types/collator.ts +0 -9
- package/types/error.ts +0 -56
- package/types/exporter.ts +0 -102
- package/types/hook.ts +0 -44
- package/types/hotmesh.ts +0 -314
- package/types/index.ts +0 -306
- package/types/job.ts +0 -233
- package/types/logger.ts +0 -8
- package/types/manifest.ts +0 -70
- package/types/map.ts +0 -5
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/meshflow.ts +0 -645
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -105
- package/types/provider.ts +0 -161
- package/types/quorum.ts +0 -167
- package/types/redis.ts +0 -404
- package/types/serializer.ts +0 -40
- package/types/stats.ts +0 -117
- package/types/stream.ts +0 -227
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
- /package/build/services/{meshflow → memflow}/workflow/all.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/all.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/context.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/context.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/didRun.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/didRun.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/emit.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/emit.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/enrich.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/enrich.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/execChild.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/hook.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/interrupt.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/interrupt.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/random.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/random.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/searchMethods.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/searchMethods.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/signal.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/signal.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/sleepFor.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/trace.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/trace.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/waitFor.d.ts +0 -0
- /package/build/types/{meshflow.js → memflow.js} +0 -0
|
@@ -1 +1,114 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Await = void 0;
|
|
4
|
+
const errors_1 = require("../../modules/errors");
|
|
5
|
+
const utils_1 = require("../../modules/utils");
|
|
6
|
+
const collator_1 = require("../collator");
|
|
7
|
+
const pipe_1 = require("../pipe");
|
|
8
|
+
const telemetry_1 = require("../telemetry");
|
|
9
|
+
const stream_1 = require("../../types/stream");
|
|
10
|
+
const activity_1 = require("./activity");
|
|
11
|
+
class Await extends activity_1.Activity {
|
|
12
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
13
|
+
super(config, data, metadata, hook, engine, context);
|
|
14
|
+
}
|
|
15
|
+
//******** INITIAL ENTRY POINT (A) ********//
|
|
16
|
+
async process() {
|
|
17
|
+
this.logger.debug('await-process', {
|
|
18
|
+
jid: this.context.metadata.jid,
|
|
19
|
+
gid: this.context.metadata.gid,
|
|
20
|
+
aid: this.metadata.aid,
|
|
21
|
+
});
|
|
22
|
+
let telemetry;
|
|
23
|
+
try {
|
|
24
|
+
await this.verifyEntry();
|
|
25
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
26
|
+
telemetry.startActivitySpan(this.leg);
|
|
27
|
+
this.mapInputData();
|
|
28
|
+
//save state and authorize reentry
|
|
29
|
+
const transaction = this.store.transact();
|
|
30
|
+
//todo: await this.registerTimeout();
|
|
31
|
+
const messageId = await this.execActivity(transaction);
|
|
32
|
+
await collator_1.CollatorService.authorizeReentry(this, transaction);
|
|
33
|
+
await this.setState(transaction);
|
|
34
|
+
await this.setStatus(0, transaction);
|
|
35
|
+
const multiResponse = (await transaction.exec());
|
|
36
|
+
//telemetry
|
|
37
|
+
telemetry.mapActivityAttributes();
|
|
38
|
+
const jobStatus = this.resolveStatus(multiResponse);
|
|
39
|
+
telemetry.setActivityAttributes({
|
|
40
|
+
'app.activity.mid': messageId,
|
|
41
|
+
'app.job.jss': jobStatus,
|
|
42
|
+
});
|
|
43
|
+
return this.context.metadata.aid;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
47
|
+
this.logger.error('await-inactive-job-error', { error });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
51
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
55
|
+
this.logger.error('await-get-state-error', { error });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
else if (error instanceof errors_1.CollationError) {
|
|
59
|
+
if (error.fault === 'duplicate') {
|
|
60
|
+
this.logger.info('await-collation-overage', {
|
|
61
|
+
job_id: this.context.metadata.jid,
|
|
62
|
+
guid: this.context.metadata.guid,
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
//unknown collation error
|
|
67
|
+
this.logger.error('await-collation-error', { error });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.logger.error('await-process-error', { error });
|
|
71
|
+
}
|
|
72
|
+
telemetry?.setActivityError(error.message);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
telemetry?.endActivitySpan();
|
|
77
|
+
this.logger.debug('await-process-end', {
|
|
78
|
+
jid: this.context.metadata.jid,
|
|
79
|
+
gid: this.context.metadata.gid,
|
|
80
|
+
aid: this.metadata.aid,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async execActivity(transaction) {
|
|
85
|
+
const topic = pipe_1.Pipe.resolve(this.config.subtype, this.context);
|
|
86
|
+
const streamData = {
|
|
87
|
+
metadata: {
|
|
88
|
+
guid: (0, utils_1.guid)(),
|
|
89
|
+
jid: this.context.metadata.jid,
|
|
90
|
+
gid: this.context.metadata.gid,
|
|
91
|
+
dad: this.metadata.dad,
|
|
92
|
+
aid: this.metadata.aid,
|
|
93
|
+
topic,
|
|
94
|
+
spn: this.context['$self'].output.metadata?.l1s,
|
|
95
|
+
trc: this.context.metadata.trc,
|
|
96
|
+
},
|
|
97
|
+
type: stream_1.StreamDataType.AWAIT,
|
|
98
|
+
data: this.context.data,
|
|
99
|
+
};
|
|
100
|
+
if (this.config.await !== true) {
|
|
101
|
+
const doAwait = pipe_1.Pipe.resolve(this.config.await, this.context);
|
|
102
|
+
if (doAwait === false) {
|
|
103
|
+
streamData.metadata.await = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (this.config.retry) {
|
|
107
|
+
streamData.policies = {
|
|
108
|
+
retry: this.config.retry,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return (await this.engine.router?.publishMessage(null, streamData, transaction));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.Await = Await;
|
|
@@ -1 +1,112 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cycle = void 0;
|
|
4
|
+
const errors_1 = require("../../modules/errors");
|
|
5
|
+
const utils_1 = require("../../modules/utils");
|
|
6
|
+
const collator_1 = require("../collator");
|
|
7
|
+
const telemetry_1 = require("../telemetry");
|
|
8
|
+
const activity_1 = require("./activity");
|
|
9
|
+
class Cycle extends activity_1.Activity {
|
|
10
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
11
|
+
super(config, data, metadata, hook, engine, context);
|
|
12
|
+
}
|
|
13
|
+
//******** LEG 1 ENTRY ********//
|
|
14
|
+
async process() {
|
|
15
|
+
this.logger.debug('cycle-process', {
|
|
16
|
+
jid: this.context.metadata.jid,
|
|
17
|
+
gid: this.context.metadata.gid,
|
|
18
|
+
aid: this.metadata.aid,
|
|
19
|
+
});
|
|
20
|
+
let telemetry;
|
|
21
|
+
try {
|
|
22
|
+
await this.verifyEntry();
|
|
23
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
24
|
+
telemetry.startActivitySpan(this.leg);
|
|
25
|
+
this.mapInputData();
|
|
26
|
+
//set state/status
|
|
27
|
+
let transaction = this.store.transact();
|
|
28
|
+
await this.setState(transaction);
|
|
29
|
+
await this.setStatus(0, transaction); //leg 1 never changes job status
|
|
30
|
+
const txResponse = (await transaction.exec());
|
|
31
|
+
telemetry.mapActivityAttributes();
|
|
32
|
+
const jobStatus = this.resolveStatus(txResponse);
|
|
33
|
+
//cycle the target ancestor
|
|
34
|
+
transaction = this.store.transact();
|
|
35
|
+
const messageId = await this.cycleAncestorActivity(transaction);
|
|
36
|
+
telemetry.setActivityAttributes({
|
|
37
|
+
'app.activity.mid': messageId,
|
|
38
|
+
'app.job.jss': jobStatus,
|
|
39
|
+
});
|
|
40
|
+
//exit early (`Cycle` activities only execute Leg 1)
|
|
41
|
+
await collator_1.CollatorService.notarizeEarlyExit(this, transaction);
|
|
42
|
+
(await transaction.exec());
|
|
43
|
+
return this.context.metadata.aid;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
47
|
+
this.logger.error('cycle-inactive-job-error', { error });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
51
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
55
|
+
this.logger.error('cycle-get-state-error', { error });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
else if (error instanceof errors_1.CollationError) {
|
|
59
|
+
if (error.fault === 'duplicate') {
|
|
60
|
+
this.logger.info('cycle-collation-overage', {
|
|
61
|
+
job_id: this.context.metadata.jid,
|
|
62
|
+
guid: this.context.metadata.guid,
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
//unknown collation error
|
|
67
|
+
this.logger.error('cycle-collation-error', { error });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.logger.error('cycle-process-error', { error });
|
|
71
|
+
}
|
|
72
|
+
telemetry?.setActivityError(error.message);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
telemetry?.endActivitySpan();
|
|
77
|
+
this.logger.debug('cycle-process-end', {
|
|
78
|
+
jid: this.context.metadata.jid,
|
|
79
|
+
gid: this.context.metadata.gid,
|
|
80
|
+
aid: this.metadata.aid,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Trigger the target ancestor to execute in a cycle,
|
|
86
|
+
* without violating the constraints of the DAG. Immutable
|
|
87
|
+
* `individual activity state` will execute in a new dimensional
|
|
88
|
+
* thread while `shared job state` can change. This
|
|
89
|
+
* pattern allows for retries without violating the DAG.
|
|
90
|
+
*/
|
|
91
|
+
async cycleAncestorActivity(transaction) {
|
|
92
|
+
//Cycle activity L1 is a standin for the target ancestor L1.
|
|
93
|
+
//Input data mapping (mapInputData) allows for the
|
|
94
|
+
//next dimensonal thread to execute with different
|
|
95
|
+
//input data than the current dimensional thread
|
|
96
|
+
this.mapInputData();
|
|
97
|
+
const streamData = {
|
|
98
|
+
metadata: {
|
|
99
|
+
guid: (0, utils_1.guid)(),
|
|
100
|
+
jid: this.context.metadata.jid,
|
|
101
|
+
gid: this.context.metadata.gid,
|
|
102
|
+
dad: collator_1.CollatorService.resolveReentryDimension(this),
|
|
103
|
+
aid: this.config.ancestor,
|
|
104
|
+
spn: this.context['$self'].output.metadata?.l1s,
|
|
105
|
+
trc: this.context.metadata.trc,
|
|
106
|
+
},
|
|
107
|
+
data: this.context.data,
|
|
108
|
+
};
|
|
109
|
+
return (await this.engine.router?.publishMessage(null, streamData, transaction));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.Cycle = Cycle;
|
|
@@ -1 +1,168 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Hook = void 0;
|
|
4
|
+
const enums_1 = require("../../modules/enums");
|
|
5
|
+
const errors_1 = require("../../modules/errors");
|
|
6
|
+
const collator_1 = require("../collator");
|
|
7
|
+
const pipe_1 = require("../pipe");
|
|
8
|
+
const task_1 = require("../task");
|
|
9
|
+
const telemetry_1 = require("../telemetry");
|
|
10
|
+
const stream_1 = require("../../types/stream");
|
|
11
|
+
const activity_1 = require("./activity");
|
|
12
|
+
/**
|
|
13
|
+
* Supports `signal hook`, `time hook`, and `cycle hook` patterns
|
|
14
|
+
*/
|
|
15
|
+
class Hook extends activity_1.Activity {
|
|
16
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
17
|
+
super(config, data, metadata, hook, engine, context);
|
|
18
|
+
}
|
|
19
|
+
//******** INITIAL ENTRY POINT (A) ********//
|
|
20
|
+
async process() {
|
|
21
|
+
this.logger.debug('hook-process', {
|
|
22
|
+
jid: this.context.metadata.jid,
|
|
23
|
+
gid: this.context.metadata.gid,
|
|
24
|
+
aid: this.metadata.aid,
|
|
25
|
+
});
|
|
26
|
+
let telemetry;
|
|
27
|
+
try {
|
|
28
|
+
await this.verifyEntry();
|
|
29
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
30
|
+
telemetry.startActivitySpan(this.leg);
|
|
31
|
+
if (this.doesHook()) {
|
|
32
|
+
//sleep and wait to awaken upon a signal
|
|
33
|
+
await this.doHook(telemetry);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
//end the activity and transition to its children
|
|
37
|
+
await this.doPassThrough(telemetry);
|
|
38
|
+
}
|
|
39
|
+
return this.context.metadata.aid;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
43
|
+
this.logger.error('hook-inactive-job-error', { error });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
47
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
51
|
+
this.logger.error('hook-get-state-error', { error });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
else if (error instanceof errors_1.CollationError) {
|
|
55
|
+
if (error.fault === 'duplicate') {
|
|
56
|
+
this.logger.info('hook-collation-overage', {
|
|
57
|
+
job_id: this.context.metadata.jid,
|
|
58
|
+
guid: this.context.metadata.guid,
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
//unknown collation error
|
|
63
|
+
this.logger.error('hook-collation-error', { error });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.logger.error('hook-process-error', { error });
|
|
67
|
+
}
|
|
68
|
+
telemetry?.setActivityError(error.message);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
telemetry?.endActivitySpan();
|
|
73
|
+
this.logger.debug('hook-process-end', {
|
|
74
|
+
jid: this.context.metadata.jid,
|
|
75
|
+
gid: this.context.metadata.gid,
|
|
76
|
+
aid: this.metadata.aid,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* does this activity use a time-hook or web-hook
|
|
82
|
+
*/
|
|
83
|
+
doesHook() {
|
|
84
|
+
if (this.config.sleep) {
|
|
85
|
+
const duration = pipe_1.Pipe.resolve(this.config.sleep, this.context);
|
|
86
|
+
return !isNaN(duration) && Number(duration) > 0;
|
|
87
|
+
}
|
|
88
|
+
return !!this.config.hook?.topic;
|
|
89
|
+
}
|
|
90
|
+
async doHook(telemetry) {
|
|
91
|
+
const transaction = this.store.transact();
|
|
92
|
+
//call registerHook separately if in cluster mode
|
|
93
|
+
//(ok to run this command multiple times if it fails),
|
|
94
|
+
//but the commands that follow must exec as a transaction
|
|
95
|
+
await this.registerHook(enums_1.HMSH_IS_CLUSTER ? undefined : transaction);
|
|
96
|
+
this.mapOutputData();
|
|
97
|
+
this.mapJobData();
|
|
98
|
+
await this.setState(transaction);
|
|
99
|
+
await collator_1.CollatorService.authorizeReentry(this, transaction);
|
|
100
|
+
await this.setStatus(0, transaction);
|
|
101
|
+
await transaction.exec();
|
|
102
|
+
telemetry.mapActivityAttributes();
|
|
103
|
+
}
|
|
104
|
+
async doPassThrough(telemetry) {
|
|
105
|
+
const transaction = this.store.transact();
|
|
106
|
+
let multiResponse;
|
|
107
|
+
this.adjacencyList = await this.filterAdjacent();
|
|
108
|
+
this.mapOutputData();
|
|
109
|
+
this.mapJobData();
|
|
110
|
+
await this.setState(transaction);
|
|
111
|
+
await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
|
|
112
|
+
await this.setStatus(this.adjacencyList.length - 1, transaction);
|
|
113
|
+
multiResponse = (await transaction.exec());
|
|
114
|
+
telemetry.mapActivityAttributes();
|
|
115
|
+
const jobStatus = this.resolveStatus(multiResponse);
|
|
116
|
+
const attrs = { 'app.job.jss': jobStatus };
|
|
117
|
+
const messageIds = await this.transition(this.adjacencyList, jobStatus);
|
|
118
|
+
if (messageIds.length) {
|
|
119
|
+
attrs['app.activity.mids'] = messageIds.join(',');
|
|
120
|
+
}
|
|
121
|
+
telemetry.setActivityAttributes(attrs);
|
|
122
|
+
}
|
|
123
|
+
async getHookRule(topic) {
|
|
124
|
+
const rules = await this.store.getHookRules();
|
|
125
|
+
return rules?.[topic]?.[0];
|
|
126
|
+
}
|
|
127
|
+
async registerHook(transaction) {
|
|
128
|
+
if (this.config.hook?.topic) {
|
|
129
|
+
return await this.engine.taskService.registerWebHook(this.config.hook.topic, this.context, this.resolveDad(), this.context.metadata.expire, transaction);
|
|
130
|
+
}
|
|
131
|
+
else if (this.config.sleep) {
|
|
132
|
+
const duration = pipe_1.Pipe.resolve(this.config.sleep, this.context);
|
|
133
|
+
await this.engine.taskService.registerTimeHook(this.context.metadata.jid, this.context.metadata.gid, `${this.metadata.aid}${this.metadata.dad || ''}`, 'sleep', duration, this.metadata.dad || '');
|
|
134
|
+
return this.context.metadata.jid;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//******** SIGNAL RE-ENTRY POINT ********//
|
|
138
|
+
async processWebHookEvent(status = stream_1.StreamStatus.SUCCESS, code = 200) {
|
|
139
|
+
this.logger.debug('hook-process-web-hook-event', {
|
|
140
|
+
topic: this.config.hook.topic,
|
|
141
|
+
aid: this.metadata.aid,
|
|
142
|
+
status,
|
|
143
|
+
code,
|
|
144
|
+
});
|
|
145
|
+
const taskService = new task_1.TaskService(this.store, this.logger);
|
|
146
|
+
const data = { ...this.data };
|
|
147
|
+
const signal = await taskService.processWebHookSignal(this.config.hook.topic, data);
|
|
148
|
+
if (signal) {
|
|
149
|
+
const [jobId, _aid, dad, gId] = signal;
|
|
150
|
+
this.context.metadata.jid = jobId;
|
|
151
|
+
this.context.metadata.gid = gId;
|
|
152
|
+
this.context.metadata.dad = dad;
|
|
153
|
+
await this.processEvent(status, code, 'hook');
|
|
154
|
+
if (code === 200) {
|
|
155
|
+
await taskService.deleteWebHookSignal(this.config.hook.topic, data);
|
|
156
|
+
} //else => 202/keep alive
|
|
157
|
+
} //else => already resolved
|
|
158
|
+
}
|
|
159
|
+
async processTimeHookEvent(jobId) {
|
|
160
|
+
this.logger.debug('hook-process-time-hook-event', {
|
|
161
|
+
jid: jobId,
|
|
162
|
+
gid: this.context.metadata.gid,
|
|
163
|
+
aid: this.metadata.aid,
|
|
164
|
+
});
|
|
165
|
+
await this.processEvent(stream_1.StreamStatus.SUCCESS, 200, 'hook');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.Hook = Hook;
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const activity_1 = require("./activity");
|
|
4
|
+
const await_1 = require("./await");
|
|
5
|
+
const cycle_1 = require("./cycle");
|
|
6
|
+
const hook_1 = require("./hook");
|
|
7
|
+
const interrupt_1 = require("./interrupt");
|
|
8
|
+
const signal_1 = require("./signal");
|
|
9
|
+
const trigger_1 = require("./trigger");
|
|
10
|
+
const worker_1 = require("./worker");
|
|
11
|
+
exports.default = {
|
|
12
|
+
activity: activity_1.Activity,
|
|
13
|
+
await: await_1.Await,
|
|
14
|
+
cycle: cycle_1.Cycle,
|
|
15
|
+
hook: hook_1.Hook,
|
|
16
|
+
interrupt: interrupt_1.Interrupt,
|
|
17
|
+
signal: signal_1.Signal,
|
|
18
|
+
trigger: trigger_1.Trigger,
|
|
19
|
+
worker: worker_1.Worker,
|
|
20
|
+
};
|
|
@@ -1 +1,158 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Interrupt = void 0;
|
|
4
|
+
const errors_1 = require("../../modules/errors");
|
|
5
|
+
const collator_1 = require("../collator");
|
|
6
|
+
const pipe_1 = require("../pipe");
|
|
7
|
+
const telemetry_1 = require("../telemetry");
|
|
8
|
+
const activity_1 = require("./activity");
|
|
9
|
+
class Interrupt extends activity_1.Activity {
|
|
10
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
11
|
+
super(config, data, metadata, hook, engine, context);
|
|
12
|
+
}
|
|
13
|
+
//******** LEG 1 ENTRY ********//
|
|
14
|
+
async process() {
|
|
15
|
+
this.logger.debug('interrupt-process', {
|
|
16
|
+
jid: this.context.metadata.jid,
|
|
17
|
+
gid: this.context.metadata.gid,
|
|
18
|
+
aid: this.metadata.aid,
|
|
19
|
+
});
|
|
20
|
+
let telemetry;
|
|
21
|
+
try {
|
|
22
|
+
await this.verifyEntry();
|
|
23
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
24
|
+
telemetry.startActivitySpan(this.leg);
|
|
25
|
+
if (this.isInterruptingSelf()) {
|
|
26
|
+
await this.interruptSelf(telemetry);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await this.interruptAnother(telemetry);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
34
|
+
this.logger.error('interrupt-inactive-job-error', { error });
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
38
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
42
|
+
this.logger.error('interrupt-get-state-error', { error });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
else if (error instanceof errors_1.CollationError) {
|
|
46
|
+
if (error.fault === 'duplicate') {
|
|
47
|
+
this.logger.info('interrupt-collation-overage', {
|
|
48
|
+
job_id: this.context.metadata.jid,
|
|
49
|
+
guid: this.context.metadata.guid,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
//unknown collation error
|
|
54
|
+
this.logger.error('interrupt-collation-error', { error });
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.logger.error('interrupt-process-error', { error });
|
|
58
|
+
}
|
|
59
|
+
telemetry?.setActivityError(error.message);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
telemetry?.endActivitySpan();
|
|
64
|
+
this.logger.debug('interrupt-process-end', {
|
|
65
|
+
jid: this.context.metadata.jid,
|
|
66
|
+
gid: this.context.metadata.gid,
|
|
67
|
+
aid: this.metadata.aid,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async interruptSelf(telemetry) {
|
|
72
|
+
// Apply final updates to THIS job's state
|
|
73
|
+
if (this.config.job?.maps) {
|
|
74
|
+
this.mapJobData();
|
|
75
|
+
await this.setState();
|
|
76
|
+
}
|
|
77
|
+
// Interrupt THIS job
|
|
78
|
+
const messageId = await this.interrupt();
|
|
79
|
+
// Notarize completion and log
|
|
80
|
+
telemetry.mapActivityAttributes();
|
|
81
|
+
const transaction = this.store.transact();
|
|
82
|
+
await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
|
|
83
|
+
await this.setStatus(-1, transaction);
|
|
84
|
+
const txResponse = (await transaction.exec());
|
|
85
|
+
const jobStatus = this.resolveStatus(txResponse);
|
|
86
|
+
telemetry.setActivityAttributes({
|
|
87
|
+
'app.activity.mid': messageId,
|
|
88
|
+
'app.job.jss': jobStatus,
|
|
89
|
+
});
|
|
90
|
+
return this.context.metadata.aid;
|
|
91
|
+
}
|
|
92
|
+
async interruptAnother(telemetry) {
|
|
93
|
+
// Interrupt ANOTHER job
|
|
94
|
+
const messageId = await this.interrupt();
|
|
95
|
+
const attrs = { 'app.activity.mid': messageId };
|
|
96
|
+
// Apply updates to THIS job's state
|
|
97
|
+
telemetry.mapActivityAttributes();
|
|
98
|
+
this.adjacencyList = await this.filterAdjacent();
|
|
99
|
+
if (this.config.job?.maps || this.config.output?.maps) {
|
|
100
|
+
this.mapOutputData();
|
|
101
|
+
this.mapJobData();
|
|
102
|
+
const transaction = this.store.transact();
|
|
103
|
+
await this.setState(transaction);
|
|
104
|
+
}
|
|
105
|
+
// Notarize completion
|
|
106
|
+
const transaction = this.store.transact();
|
|
107
|
+
await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
|
|
108
|
+
await this.setStatus(this.adjacencyList.length - 1, transaction);
|
|
109
|
+
const txResponse = (await transaction.exec());
|
|
110
|
+
const jobStatus = this.resolveStatus(txResponse);
|
|
111
|
+
attrs['app.job.jss'] = jobStatus;
|
|
112
|
+
// Transition next generation and log
|
|
113
|
+
const messageIds = await this.transition(this.adjacencyList, jobStatus);
|
|
114
|
+
if (messageIds.length) {
|
|
115
|
+
attrs['app.activity.mids'] = messageIds.join(',');
|
|
116
|
+
}
|
|
117
|
+
telemetry.setActivityAttributes(attrs);
|
|
118
|
+
return this.context.metadata.aid;
|
|
119
|
+
}
|
|
120
|
+
isInterruptingSelf() {
|
|
121
|
+
if (!this.config.target) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
const resolvedJob = pipe_1.Pipe.resolve(this.config.target, this.context);
|
|
125
|
+
return resolvedJob == this.context.metadata.jid;
|
|
126
|
+
}
|
|
127
|
+
resolveInterruptOptions() {
|
|
128
|
+
return {
|
|
129
|
+
reason: this.config.reason !== undefined
|
|
130
|
+
? pipe_1.Pipe.resolve(this.config.reason, this.context)
|
|
131
|
+
: undefined,
|
|
132
|
+
throw: this.config.throw !== undefined
|
|
133
|
+
? pipe_1.Pipe.resolve(this.config.throw, this.context)
|
|
134
|
+
: undefined,
|
|
135
|
+
descend: this.config.descend !== undefined
|
|
136
|
+
? pipe_1.Pipe.resolve(this.config.descend, this.context)
|
|
137
|
+
: undefined,
|
|
138
|
+
code: this.config.code !== undefined
|
|
139
|
+
? pipe_1.Pipe.resolve(this.config.code, this.context)
|
|
140
|
+
: undefined,
|
|
141
|
+
expire: this.config.expire !== undefined
|
|
142
|
+
? pipe_1.Pipe.resolve(this.config.expire, this.context)
|
|
143
|
+
: undefined,
|
|
144
|
+
stack: this.config.stack !== undefined
|
|
145
|
+
? pipe_1.Pipe.resolve(this.config.stack, this.context)
|
|
146
|
+
: undefined,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async interrupt() {
|
|
150
|
+
const options = this.resolveInterruptOptions();
|
|
151
|
+
return await this.engine.interrupt(this.config.topic !== undefined
|
|
152
|
+
? pipe_1.Pipe.resolve(this.config.topic, this.context)
|
|
153
|
+
: this.context.metadata.tpc, this.config.target !== undefined
|
|
154
|
+
? pipe_1.Pipe.resolve(this.config.target, this.context)
|
|
155
|
+
: this.context.metadata.jid, options);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.Interrupt = Interrupt;
|