@hahnpro/flow-sdk 4.20.11-0 → 4.20.11
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { CloudEvent } from 'cloudevents';
|
|
2
|
+
import type { CloudEvent } from 'cloudevents';
|
|
3
3
|
import { PartialObserver } from 'rxjs';
|
|
4
4
|
import { API } from '@hahnpro/hpc-api';
|
|
5
5
|
import { AmqpConnection, Nack } from './amqp';
|
|
6
|
-
import { ClassType, Flow, FlowElementContext } from './flow.interface';
|
|
6
|
+
import type { ClassType, Flow, FlowElementContext } from './flow.interface';
|
|
7
7
|
import type { FlowEvent } from './FlowEvent';
|
|
8
8
|
import { Logger } from './FlowLogger';
|
|
9
9
|
import { RpcClient } from './RpcClient';
|
|
@@ -21,7 +21,6 @@ export declare class FlowApplication {
|
|
|
21
21
|
private _rpcClient;
|
|
22
22
|
constructor(modules: ClassType<any>[], flow: Flow, logger?: Logger, amqpConnection?: AmqpConnection, skipApi?: boolean);
|
|
23
23
|
private init;
|
|
24
|
-
private publishLifecycleEvent;
|
|
25
24
|
private setQueueMetrics;
|
|
26
25
|
private updateMetrics;
|
|
27
26
|
subscribe: (streamId: string, observer: PartialObserver<FlowEvent>) => import("rxjs").Subscription;
|
package/dist/FlowApplication.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FlowApplication = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
require("reflect-metadata");
|
|
6
|
-
const cloudevents_1 = require("cloudevents");
|
|
7
6
|
const object_sizeof_1 = tslib_1.__importDefault(require("object-sizeof"));
|
|
8
7
|
const perf_hooks_1 = require("perf_hooks");
|
|
9
8
|
const rxjs_1 = require("rxjs");
|
|
@@ -12,7 +11,6 @@ const uuid_1 = require("uuid");
|
|
|
12
11
|
const hpc_api_1 = require("@hahnpro/hpc-api");
|
|
13
12
|
const amqp_1 = require("./amqp");
|
|
14
13
|
const utils_1 = require("./utils");
|
|
15
|
-
const flow_interface_1 = require("./flow.interface");
|
|
16
14
|
const FlowLogger_1 = require("./FlowLogger");
|
|
17
15
|
const RpcClient_1 = require("./RpcClient");
|
|
18
16
|
const MAX_EVENT_SIZE_BYTES = +process.env.MAX_EVENT_SIZE_BYTES || 512 * 1024;
|
|
@@ -26,24 +24,6 @@ class FlowApplication {
|
|
|
26
24
|
this.outputStreamMap = new Map();
|
|
27
25
|
this.outputQueueMetrics = new Map();
|
|
28
26
|
this.performanceMap = new Map();
|
|
29
|
-
this.publishLifecycleEvent = (flowEvent, eventType, date = new Date()) => {
|
|
30
|
-
if (!this.amqpConnection) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const event = new cloudevents_1.CloudEvent({
|
|
35
|
-
source: flowEvent.getSource(),
|
|
36
|
-
type: eventType,
|
|
37
|
-
data: Object.assign(Object.assign({}, flowEvent.getMetadata()), { flowEventId: flowEvent.getId() }),
|
|
38
|
-
time: date.toISOString(),
|
|
39
|
-
});
|
|
40
|
-
const message = event.toJSON();
|
|
41
|
-
return this.amqpConnection.publish('flow', 'lifecycle', message);
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
this.logger.error(err);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
27
|
this.setQueueMetrics = (id) => {
|
|
48
28
|
const metrics = this.outputQueueMetrics.get(id) || { size: 0, lastAdd: 0, lastRemove: Date.now(), warnings: 0 };
|
|
49
29
|
const secsProcessing = Math.round((metrics.lastAdd - metrics.lastRemove) / 1000);
|
|
@@ -213,7 +193,6 @@ class FlowApplication {
|
|
|
213
193
|
try {
|
|
214
194
|
await this.amqpConnection.managedChannel.assertExchange('deployment', 'direct', { durable: true });
|
|
215
195
|
await this.amqpConnection.managedChannel.assertExchange('flowlogs', 'fanout', { durable: true });
|
|
216
|
-
await this.amqpConnection.managedChannel.assertExchange('flow', 'direct', { durable: true });
|
|
217
196
|
}
|
|
218
197
|
catch (e) {
|
|
219
198
|
logErrorAndExit(`Could not assert exchanges: ${e}`);
|
|
@@ -281,13 +260,10 @@ class FlowApplication {
|
|
|
281
260
|
outputStream
|
|
282
261
|
.pipe((0, operators_1.tap)(() => this.setQueueMetrics(targetStreamId)), (0, operators_1.mergeMap)(async (event) => {
|
|
283
262
|
this.performanceMap.set(event.getId(), perf_hooks_1.performance.eventLoopUtilization());
|
|
284
|
-
this.publishLifecycleEvent(event, flow_interface_1.LifecycleEvent.ACTIVATED);
|
|
285
263
|
try {
|
|
286
264
|
await element[streamHandler](event);
|
|
287
|
-
this.publishLifecycleEvent(event, flow_interface_1.LifecycleEvent.COMPLETED);
|
|
288
265
|
}
|
|
289
266
|
catch (err) {
|
|
290
|
-
this.publishLifecycleEvent(event, flow_interface_1.LifecycleEvent.TERMINATED);
|
|
291
267
|
try {
|
|
292
268
|
element.handleApiError(err);
|
|
293
269
|
}
|
|
@@ -302,8 +278,8 @@ class FlowApplication {
|
|
|
302
278
|
if (elu) {
|
|
303
279
|
this.performanceMap.delete(event.getId());
|
|
304
280
|
elu = perf_hooks_1.performance.eventLoopUtilization(elu);
|
|
305
|
-
if (elu.utilization > 0.
|
|
306
|
-
this.logger.warn(`High event loop utilization detected for ${targetStreamId} with event ${event.getId()}! Handler
|
|
281
|
+
if (elu.utilization > 0.7 && elu.active > 1000) {
|
|
282
|
+
this.logger.warn(`High event loop utilization detected for ${targetStreamId} with event ${event.getId()}! Handler has been active for ${Number(elu.active).toFixed(2)}ms with a utilization of ${Number(elu.utilization * 100).toFixed(2)}%. Consider refactoring or move tasks to a worker thread.`);
|
|
307
283
|
}
|
|
308
284
|
}
|
|
309
285
|
}))
|
package/dist/FlowElement.js
CHANGED
|
@@ -126,7 +126,7 @@ function InputStream(id = 'default', options) {
|
|
|
126
126
|
if (!this.stopPropagateStream.has(id)) {
|
|
127
127
|
this.stopPropagateStream.set(id, (_a = options === null || options === void 0 ? void 0 : options.stopPropagation) !== null && _a !== void 0 ? _a : false);
|
|
128
128
|
}
|
|
129
|
-
return method.call(this, new FlowEvent_1.FlowEvent(Object.assign(Object.assign({
|
|
129
|
+
return method.call(this, new FlowEvent_1.FlowEvent(Object.assign(Object.assign({}, event.getMetadata()), { inputStreamId: id }), event.getData(), event.getType(), new Date(event.getTime())));
|
|
130
130
|
};
|
|
131
131
|
};
|
|
132
132
|
}
|
package/dist/FlowEvent.d.ts
CHANGED
|
@@ -8,13 +8,7 @@ export declare class FlowEvent {
|
|
|
8
8
|
getDataContentType: () => string;
|
|
9
9
|
getDataschema: () => string;
|
|
10
10
|
getId: () => string;
|
|
11
|
-
getMetadata: () =>
|
|
12
|
-
deploymentId: string;
|
|
13
|
-
elementId: string;
|
|
14
|
-
flowId: string;
|
|
15
|
-
functionFqn: string;
|
|
16
|
-
inputStreamId: string;
|
|
17
|
-
};
|
|
11
|
+
getMetadata: () => any;
|
|
18
12
|
getSource: () => string;
|
|
19
13
|
getStreamId: () => string;
|
|
20
14
|
getSubject: () => string;
|
package/dist/FlowModule.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlowModule = void 0;
|
|
4
4
|
function FlowModule(metadata) {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
7
|
-
throw new Error(`Flow Module name (${metadata.name}) is not valid`);
|
|
5
|
+
const validateNameRegExp = new RegExp(/^(@[a-z][a-z0-9-]*\/)?[a-z][a-z0-9-]*$/);
|
|
6
|
+
if (!validateNameRegExp.test(metadata.name)) {
|
|
7
|
+
throw new Error(`Flow Module name (${metadata.name}) is not valid. Name must be all lowercase and not contain any special characters except for hyphens. Can optionally start with a scope "@scopename/"`);
|
|
8
8
|
}
|
|
9
9
|
return (target) => {
|
|
10
10
|
Reflect.defineMetadata('module:name', metadata.name, target);
|
package/dist/flow.interface.d.ts
CHANGED
|
@@ -38,9 +38,4 @@ export interface StreamOptions {
|
|
|
38
38
|
concurrent?: number;
|
|
39
39
|
}
|
|
40
40
|
export declare type ClassType<T> = new (...args: any[]) => T;
|
|
41
|
-
export declare enum LifecycleEvent {
|
|
42
|
-
ACTIVATED = "com.hahnpro.flow_function.activated",
|
|
43
|
-
COMPLETED = "com.hahnpro.flow_function.completed",
|
|
44
|
-
TERMINATED = "com.hahnpro.flow_function.terminated"
|
|
45
|
-
}
|
|
46
41
|
export {};
|
package/dist/flow.interface.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LifecycleEvent = void 0;
|
|
4
|
-
var LifecycleEvent;
|
|
5
|
-
(function (LifecycleEvent) {
|
|
6
|
-
LifecycleEvent["ACTIVATED"] = "com.hahnpro.flow_function.activated";
|
|
7
|
-
LifecycleEvent["COMPLETED"] = "com.hahnpro.flow_function.completed";
|
|
8
|
-
LifecycleEvent["TERMINATED"] = "com.hahnpro.flow_function.terminated";
|
|
9
|
-
})(LifecycleEvent = exports.LifecycleEvent || (exports.LifecycleEvent = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hahnpro/flow-sdk",
|
|
3
|
-
"version": "4.20.11
|
|
3
|
+
"version": "4.20.11",
|
|
4
4
|
"description": "SDK for building Flow Modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@hahnpro/hpc-api": "2.3.1",
|
|
28
28
|
"amqp-connection-manager": "^3.9.0",
|
|
29
|
-
"amqplib": "^0.
|
|
29
|
+
"amqplib": "^0.9.0",
|
|
30
30
|
"class-transformer": "0.5.1",
|
|
31
31
|
"class-validator": "~0.13.2",
|
|
32
32
|
"cloudevents": "^6.0.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@types/amqplib": "^0.8.2",
|
|
46
46
|
"@types/jest": "^27.5.0",
|
|
47
47
|
"@types/lodash": "^4.14.182",
|
|
48
|
-
"@types/node": "^16.11.
|
|
48
|
+
"@types/node": "^16.11.34",
|
|
49
49
|
"class-validator-jsonschema": "^3.1.0",
|
|
50
50
|
"jest": "^27.5.1",
|
|
51
51
|
"typescript": "^4.6.4"
|