@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,134 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Signal = void 0;
|
|
4
|
+
const errors_1 = require("../../modules/errors");
|
|
5
|
+
const collator_1 = require("../collator");
|
|
6
|
+
const mapper_1 = require("../mapper");
|
|
7
|
+
const pipe_1 = require("../pipe");
|
|
8
|
+
const telemetry_1 = require("../telemetry");
|
|
9
|
+
const activity_1 = require("./activity");
|
|
10
|
+
class Signal extends activity_1.Activity {
|
|
11
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
12
|
+
super(config, data, metadata, hook, engine, context);
|
|
13
|
+
}
|
|
14
|
+
//******** LEG 1 ENTRY ********//
|
|
15
|
+
async process() {
|
|
16
|
+
this.logger.debug('signal-process', {
|
|
17
|
+
jid: this.context.metadata.jid,
|
|
18
|
+
gid: this.context.metadata.gid,
|
|
19
|
+
aid: this.metadata.aid,
|
|
20
|
+
});
|
|
21
|
+
let telemetry;
|
|
22
|
+
try {
|
|
23
|
+
await this.verifyEntry();
|
|
24
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
25
|
+
telemetry.startActivitySpan(this.leg);
|
|
26
|
+
//save state and notarize early completion (signals only run leg1)
|
|
27
|
+
const transaction = this.store.transact();
|
|
28
|
+
this.adjacencyList = await this.filterAdjacent();
|
|
29
|
+
this.mapOutputData();
|
|
30
|
+
this.mapJobData();
|
|
31
|
+
await this.setState(transaction);
|
|
32
|
+
await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
|
|
33
|
+
await this.setStatus(this.adjacencyList.length - 1, transaction);
|
|
34
|
+
const multiResponse = (await transaction.exec());
|
|
35
|
+
//todo: this should execute BEFORE the status is decremented
|
|
36
|
+
if (this.config.subtype === 'all') {
|
|
37
|
+
await this.hookAll();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await this.hookOne();
|
|
41
|
+
}
|
|
42
|
+
//transition to adjacent activities
|
|
43
|
+
const jobStatus = this.resolveStatus(multiResponse);
|
|
44
|
+
const attrs = { 'app.job.jss': jobStatus };
|
|
45
|
+
const messageIds = await this.transition(this.adjacencyList, jobStatus);
|
|
46
|
+
if (messageIds.length) {
|
|
47
|
+
attrs['app.activity.mids'] = messageIds.join(',');
|
|
48
|
+
}
|
|
49
|
+
telemetry.mapActivityAttributes();
|
|
50
|
+
telemetry.setActivityAttributes(attrs);
|
|
51
|
+
return this.context.metadata.aid;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
55
|
+
this.logger.error('signal-inactive-job-error', { error });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
59
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
63
|
+
this.logger.error('signal-get-state-error', { error });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
else if (error instanceof errors_1.CollationError) {
|
|
67
|
+
if (error.fault === 'duplicate') {
|
|
68
|
+
this.logger.info('signal-collation-overage', {
|
|
69
|
+
job_id: this.context.metadata.jid,
|
|
70
|
+
guid: this.context.metadata.guid,
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
//unknown collation error
|
|
75
|
+
this.logger.error('signal-collation-error', { error });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.logger.error('signal-process-error', { error });
|
|
79
|
+
}
|
|
80
|
+
telemetry?.setActivityError(error.message);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
telemetry?.endActivitySpan();
|
|
85
|
+
this.logger.debug('signal-process-end', {
|
|
86
|
+
jid: this.context.metadata.jid,
|
|
87
|
+
gid: this.context.metadata.gid,
|
|
88
|
+
aid: this.metadata.aid,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
mapSignalData() {
|
|
93
|
+
if (this.config.signal?.maps) {
|
|
94
|
+
const mapper = new mapper_1.MapperService(this.config.signal.maps, this.context);
|
|
95
|
+
return mapper.mapRules();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
mapResolverData() {
|
|
99
|
+
if (this.config.resolver?.maps) {
|
|
100
|
+
const mapper = new mapper_1.MapperService(this.config.resolver.maps, this.context);
|
|
101
|
+
return mapper.mapRules();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The signal activity will hook one
|
|
106
|
+
*/
|
|
107
|
+
async hookOne() {
|
|
108
|
+
const topic = pipe_1.Pipe.resolve(this.config.topic, this.context);
|
|
109
|
+
const signalInputData = this.mapSignalData();
|
|
110
|
+
const status = pipe_1.Pipe.resolve(this.config.status, this.context);
|
|
111
|
+
const code = pipe_1.Pipe.resolve(this.config.code, this.context);
|
|
112
|
+
return await this.engine.hook(topic, signalInputData, status, code);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The signal activity will hook all paused jobs that share the same job key.
|
|
116
|
+
*/
|
|
117
|
+
async hookAll() {
|
|
118
|
+
//prep 1) generate `input signal data` (essentially the webhook payload)
|
|
119
|
+
const signalInputData = this.mapSignalData();
|
|
120
|
+
//prep 2) generate data that resolves the job key (per the YAML config)
|
|
121
|
+
const keyResolverData = this.mapResolverData();
|
|
122
|
+
if (this.config.scrub) {
|
|
123
|
+
//self-clean the indexes upon use if configured
|
|
124
|
+
keyResolverData.scrub = true;
|
|
125
|
+
}
|
|
126
|
+
//prep 3) jobKeys can contain multiple indexes (per the YAML config)
|
|
127
|
+
const key_name = pipe_1.Pipe.resolve(this.config.key_name, this.context);
|
|
128
|
+
const key_value = pipe_1.Pipe.resolve(this.config.key_value, this.context);
|
|
129
|
+
const indexQueryFacets = [`${key_name}:${key_value}`];
|
|
130
|
+
//execute: `hookAll` will now resume all paused jobs that share the same job key
|
|
131
|
+
return await this.engine.hookAll(this.config.topic, signalInputData, keyResolverData, indexQueryFacets);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.Signal = Signal;
|
|
@@ -1 +1,246 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trigger = 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 reporter_1 = require("../reporter");
|
|
9
|
+
const serializer_1 = require("../serializer");
|
|
10
|
+
const telemetry_1 = require("../telemetry");
|
|
11
|
+
const activity_1 = require("./activity");
|
|
12
|
+
class Trigger extends activity_1.Activity {
|
|
13
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
14
|
+
super(config, data, metadata, hook, engine, context);
|
|
15
|
+
}
|
|
16
|
+
async process(options) {
|
|
17
|
+
this.logger.debug('trigger-process', {
|
|
18
|
+
subscribes: this.config.subscribes,
|
|
19
|
+
});
|
|
20
|
+
let telemetry;
|
|
21
|
+
try {
|
|
22
|
+
this.setLeg(2);
|
|
23
|
+
await this.getState();
|
|
24
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
25
|
+
telemetry.startJobSpan();
|
|
26
|
+
telemetry.startActivitySpan(this.leg);
|
|
27
|
+
this.mapJobData();
|
|
28
|
+
this.adjacencyList = await this.filterAdjacent();
|
|
29
|
+
const initialStatus = this.initStatus(options, this.adjacencyList.length);
|
|
30
|
+
await this.setStateNX(initialStatus);
|
|
31
|
+
await this.setStatus(initialStatus);
|
|
32
|
+
this.bindSearchData(options);
|
|
33
|
+
this.bindMarkerData(options);
|
|
34
|
+
const transaction = this.store.transact();
|
|
35
|
+
await this.setState(transaction);
|
|
36
|
+
await this.setStats(transaction);
|
|
37
|
+
if (options?.pending) {
|
|
38
|
+
await this.setExpired(options?.pending, transaction);
|
|
39
|
+
}
|
|
40
|
+
await collator_1.CollatorService.notarizeInception(this, this.context.metadata.guid, transaction);
|
|
41
|
+
await transaction.exec();
|
|
42
|
+
this.execAdjacentParent();
|
|
43
|
+
telemetry.mapActivityAttributes();
|
|
44
|
+
const jobStatus = Number(this.context.metadata.js);
|
|
45
|
+
telemetry.setJobAttributes({ 'app.job.jss': jobStatus });
|
|
46
|
+
const attrs = { 'app.job.jss': jobStatus };
|
|
47
|
+
await this.transitionAndLogAdjacent(options, jobStatus, attrs);
|
|
48
|
+
telemetry.setActivityAttributes(attrs);
|
|
49
|
+
return this.context.metadata.jid;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
telemetry?.setActivityError(error.message);
|
|
53
|
+
if (error instanceof errors_1.DuplicateJobError) {
|
|
54
|
+
//todo: verify baseline in x-AZ rollover
|
|
55
|
+
await (0, utils_1.sleepFor)(1000);
|
|
56
|
+
const isOverage = await collator_1.CollatorService.isInceptionOverage(this, this.context.metadata.guid);
|
|
57
|
+
if (isOverage) {
|
|
58
|
+
this.logger.info('trigger-collation-overage', {
|
|
59
|
+
job_id: error.jobId,
|
|
60
|
+
guid: this.context.metadata.guid,
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.logger.error('duplicate-job-error', {
|
|
65
|
+
job_id: error.jobId,
|
|
66
|
+
guid: this.context.metadata.guid,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.logger.error('trigger-process-error', { error });
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
telemetry?.endJobSpan();
|
|
76
|
+
telemetry?.endActivitySpan();
|
|
77
|
+
this.logger.debug('trigger-process-end', {
|
|
78
|
+
subscribes: this.config.subscribes,
|
|
79
|
+
jid: this.context.metadata.jid,
|
|
80
|
+
gid: this.context.metadata.gid,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async transitionAndLogAdjacent(options = {}, jobStatus, attrs) {
|
|
85
|
+
//todo: enable resume from pending state
|
|
86
|
+
if (isNaN(options.pending)) {
|
|
87
|
+
const messageIds = await this.transition(this.adjacencyList, jobStatus);
|
|
88
|
+
if (messageIds.length) {
|
|
89
|
+
attrs['app.activity.mids'] = messageIds.join(',');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* `pending` flows will not transition from the trigger to adjacent children until resumed
|
|
95
|
+
*/
|
|
96
|
+
initStatus(options = {}, count) {
|
|
97
|
+
if (options.pending) {
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
return count;
|
|
101
|
+
}
|
|
102
|
+
async setExpired(seconds, transaction) {
|
|
103
|
+
await this.store.expireJob(this.context.metadata.jid, seconds, transaction);
|
|
104
|
+
}
|
|
105
|
+
safeKey(key) {
|
|
106
|
+
return `_${key}`;
|
|
107
|
+
}
|
|
108
|
+
bindSearchData(options) {
|
|
109
|
+
if (options?.search) {
|
|
110
|
+
Object.keys(options.search).forEach((key) => {
|
|
111
|
+
this.context.data[this.safeKey(key)] = options.search[key].toString();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
bindMarkerData(options) {
|
|
116
|
+
if (options?.marker) {
|
|
117
|
+
Object.keys(options.marker).forEach((key) => {
|
|
118
|
+
if (key.startsWith('-')) {
|
|
119
|
+
this.context.data[key] = options.marker[key].toString();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async setStatus(amount) {
|
|
125
|
+
this.context.metadata.js = amount;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* if the parent (spawner) chose not to await, emit the job_id
|
|
129
|
+
* as the data payload { job_id }
|
|
130
|
+
*/
|
|
131
|
+
async execAdjacentParent() {
|
|
132
|
+
if (this.context.metadata.px) {
|
|
133
|
+
const timestamp = (0, utils_1.formatISODate)(new Date());
|
|
134
|
+
const jobStartedConfirmationMessage = {
|
|
135
|
+
metadata: this.context.metadata,
|
|
136
|
+
data: {
|
|
137
|
+
job_id: this.context.metadata.jid,
|
|
138
|
+
jc: timestamp,
|
|
139
|
+
ju: timestamp,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
await this.engine.execAdjacentParent(this.context, jobStartedConfirmationMessage);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
createInputContext() {
|
|
146
|
+
const input = {
|
|
147
|
+
[this.metadata.aid]: {
|
|
148
|
+
input: { data: this.data },
|
|
149
|
+
},
|
|
150
|
+
$self: {
|
|
151
|
+
input: { data: this.data },
|
|
152
|
+
output: { data: this.data },
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
return input;
|
|
156
|
+
}
|
|
157
|
+
async getState() {
|
|
158
|
+
const inputContext = this.createInputContext();
|
|
159
|
+
const jobId = this.resolveJobId(inputContext);
|
|
160
|
+
const jobKey = this.resolveJobKey(inputContext);
|
|
161
|
+
const utc = (0, utils_1.formatISODate)(new Date());
|
|
162
|
+
const { id, version } = await this.engine.getVID();
|
|
163
|
+
this.initDimensionalAddress(collator_1.CollatorService.getDimensionalSeed());
|
|
164
|
+
const activityMetadata = {
|
|
165
|
+
...this.metadata,
|
|
166
|
+
jid: jobId,
|
|
167
|
+
key: jobKey,
|
|
168
|
+
as: collator_1.CollatorService.getTriggerSeed(),
|
|
169
|
+
};
|
|
170
|
+
this.context = {
|
|
171
|
+
metadata: {
|
|
172
|
+
...this.metadata,
|
|
173
|
+
gid: (0, utils_1.guid)(),
|
|
174
|
+
ngn: this.context.metadata.ngn,
|
|
175
|
+
pj: this.context.metadata.pj,
|
|
176
|
+
pg: this.context.metadata.pg,
|
|
177
|
+
pd: this.context.metadata.pd,
|
|
178
|
+
pa: this.context.metadata.pa,
|
|
179
|
+
px: this.context.metadata.px,
|
|
180
|
+
app: id,
|
|
181
|
+
vrs: version,
|
|
182
|
+
tpc: this.config.subscribes,
|
|
183
|
+
trc: this.context.metadata.trc,
|
|
184
|
+
spn: this.context.metadata.spn,
|
|
185
|
+
guid: this.context.metadata.guid,
|
|
186
|
+
jid: jobId,
|
|
187
|
+
dad: collator_1.CollatorService.getDimensionalSeed(),
|
|
188
|
+
key: jobKey,
|
|
189
|
+
jc: utc,
|
|
190
|
+
ju: utc,
|
|
191
|
+
ts: (0, utils_1.getTimeSeries)(this.resolveGranularity()),
|
|
192
|
+
js: 0,
|
|
193
|
+
},
|
|
194
|
+
data: {},
|
|
195
|
+
[this.metadata.aid]: {
|
|
196
|
+
input: {
|
|
197
|
+
data: this.data,
|
|
198
|
+
metadata: activityMetadata,
|
|
199
|
+
},
|
|
200
|
+
output: {
|
|
201
|
+
data: this.data,
|
|
202
|
+
metadata: activityMetadata,
|
|
203
|
+
},
|
|
204
|
+
settings: { data: {} },
|
|
205
|
+
errors: { data: {} },
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
this.context['$self'] = this.context[this.metadata.aid];
|
|
209
|
+
this.context['$job'] = this.context; //NEVER call STRINGIFY! (circular)
|
|
210
|
+
}
|
|
211
|
+
bindJobMetadataPaths() {
|
|
212
|
+
return serializer_1.MDATA_SYMBOLS.JOB.KEYS.map((key) => `metadata/${key}`);
|
|
213
|
+
}
|
|
214
|
+
bindActivityMetadataPaths() {
|
|
215
|
+
return serializer_1.MDATA_SYMBOLS.ACTIVITY.KEYS.map((key) => `output/metadata/${key}`);
|
|
216
|
+
}
|
|
217
|
+
resolveGranularity() {
|
|
218
|
+
return (this.config.stats?.granularity || reporter_1.ReporterService.DEFAULT_GRANULARITY);
|
|
219
|
+
}
|
|
220
|
+
getJobStatus() {
|
|
221
|
+
return this.context.metadata.js;
|
|
222
|
+
}
|
|
223
|
+
resolveJobId(context) {
|
|
224
|
+
const jobId = this.config.stats?.id;
|
|
225
|
+
return jobId ? pipe_1.Pipe.resolve(jobId, context) : (0, utils_1.guid)();
|
|
226
|
+
}
|
|
227
|
+
resolveJobKey(context) {
|
|
228
|
+
const jobKey = this.config.stats?.key;
|
|
229
|
+
return jobKey ? pipe_1.Pipe.resolve(jobKey, context) : '';
|
|
230
|
+
}
|
|
231
|
+
async setStateNX(status) {
|
|
232
|
+
const jobId = this.context.metadata.jid;
|
|
233
|
+
if (!await this.store.setStateNX(jobId, this.engine.appId, status)) {
|
|
234
|
+
throw new errors_1.DuplicateJobError(jobId);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async setStats(transaction) {
|
|
238
|
+
const md = this.context.metadata;
|
|
239
|
+
if (md.key && this.config.stats?.measures) {
|
|
240
|
+
const config = await this.engine.getVID();
|
|
241
|
+
const reporter = new reporter_1.ReporterService(config, this.store, this.logger);
|
|
242
|
+
await this.store.setStats(md.key, md.jid, md.ts, reporter.resolveTriggerStatistics(this.config, this.context), config, transaction);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.Trigger = Trigger;
|
|
@@ -1 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Worker = 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 activity_1 = require("./activity");
|
|
10
|
+
class Worker extends activity_1.Activity {
|
|
11
|
+
constructor(config, data, metadata, hook, engine, context) {
|
|
12
|
+
super(config, data, metadata, hook, engine, context);
|
|
13
|
+
}
|
|
14
|
+
//******** INITIAL ENTRY POINT (A) ********//
|
|
15
|
+
async process() {
|
|
16
|
+
this.logger.debug('worker-process', {
|
|
17
|
+
jid: this.context.metadata.jid,
|
|
18
|
+
gid: this.context.metadata.gid,
|
|
19
|
+
aid: this.metadata.aid,
|
|
20
|
+
});
|
|
21
|
+
let telemetry;
|
|
22
|
+
try {
|
|
23
|
+
await this.verifyEntry();
|
|
24
|
+
telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
|
|
25
|
+
telemetry.startActivitySpan(this.leg);
|
|
26
|
+
this.mapInputData();
|
|
27
|
+
//save state and authorize reentry
|
|
28
|
+
const transaction = this.store.transact();
|
|
29
|
+
//todo: await this.registerTimeout();
|
|
30
|
+
const messageId = await this.execActivity(transaction);
|
|
31
|
+
await collator_1.CollatorService.authorizeReentry(this, transaction);
|
|
32
|
+
await this.setState(transaction);
|
|
33
|
+
await this.setStatus(0, transaction);
|
|
34
|
+
const txResponse = (await transaction.exec());
|
|
35
|
+
//telemetry
|
|
36
|
+
telemetry.mapActivityAttributes();
|
|
37
|
+
const jobStatus = this.resolveStatus(txResponse);
|
|
38
|
+
telemetry.setActivityAttributes({
|
|
39
|
+
'app.activity.mid': messageId,
|
|
40
|
+
'app.job.jss': jobStatus,
|
|
41
|
+
});
|
|
42
|
+
return this.context.metadata.aid;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof errors_1.InactiveJobError) {
|
|
46
|
+
this.logger.error('await-inactive-job-error', { error });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
else if (error instanceof errors_1.GenerationalError) {
|
|
50
|
+
this.logger.info('process-event-generational-job-error', { error });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
else if (error instanceof errors_1.GetStateError) {
|
|
54
|
+
this.logger.error('worker-get-state-error', { error });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
else if (error instanceof errors_1.CollationError) {
|
|
58
|
+
if (error.fault === 'duplicate') {
|
|
59
|
+
this.logger.info('worker-collation-overage', {
|
|
60
|
+
job_id: this.context.metadata.jid,
|
|
61
|
+
guid: this.context.metadata.guid,
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
//unknown collation error
|
|
66
|
+
this.logger.error('worker-collation-error', { error });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.logger.error('worker-process-error', { error });
|
|
70
|
+
}
|
|
71
|
+
telemetry?.setActivityError(error.message);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
telemetry?.endActivitySpan();
|
|
76
|
+
this.logger.debug('worker-process-end', {
|
|
77
|
+
jid: this.context.metadata.jid,
|
|
78
|
+
gid: this.context.metadata.gid,
|
|
79
|
+
aid: this.metadata.aid,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async execActivity(transaction) {
|
|
84
|
+
const topic = pipe_1.Pipe.resolve(this.config.subtype, this.context);
|
|
85
|
+
const streamData = {
|
|
86
|
+
metadata: {
|
|
87
|
+
guid: (0, utils_1.guid)(),
|
|
88
|
+
jid: this.context.metadata.jid,
|
|
89
|
+
gid: this.context.metadata.gid,
|
|
90
|
+
dad: this.metadata.dad,
|
|
91
|
+
aid: this.metadata.aid,
|
|
92
|
+
topic,
|
|
93
|
+
spn: this.context['$self'].output.metadata.l1s,
|
|
94
|
+
trc: this.context.metadata.trc,
|
|
95
|
+
},
|
|
96
|
+
data: this.context.data,
|
|
97
|
+
};
|
|
98
|
+
if (this.config.retry) {
|
|
99
|
+
streamData.policies = {
|
|
100
|
+
retry: this.config.retry,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return (await this.engine.router?.publishMessage(topic, streamData, transaction));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.Worker = Worker;
|