@hahnpro/flow-sdk 9.3.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FlowApplication.js +21 -11
- package/dist/FlowLogger.js +7 -1
- package/dist/nats.js +1 -2
- package/package.json +4 -4
package/dist/FlowApplication.js
CHANGED
|
@@ -178,15 +178,15 @@ class FlowApplication {
|
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
try {
|
|
181
|
-
const
|
|
182
|
-
if ((0, object_sizeof_1.default)(
|
|
183
|
-
|
|
181
|
+
const formatedEvent = event.format();
|
|
182
|
+
if ((0, object_sizeof_1.default)(formatedEvent) > MAX_EVENT_SIZE_BYTES) {
|
|
183
|
+
formatedEvent.data = (0, utils_1.truncate)(formatedEvent.data);
|
|
184
184
|
}
|
|
185
185
|
const natsEvent = {
|
|
186
186
|
source: `hpc/flow-application`,
|
|
187
187
|
type: `${nats_1.natsFlowsPrefixFlowDeployment}.flowlogs`,
|
|
188
188
|
subject: `${this.context.deploymentId}`,
|
|
189
|
-
data:
|
|
189
|
+
data: formatedEvent,
|
|
190
190
|
};
|
|
191
191
|
await (0, nats_1.publishNatsEvent)(this.logger, this.natsConnection, natsEvent);
|
|
192
192
|
return true;
|
|
@@ -251,11 +251,11 @@ class FlowApplication {
|
|
|
251
251
|
getProperties() {
|
|
252
252
|
return this.contextManager.getProperties();
|
|
253
253
|
}
|
|
254
|
-
async consumeNatsMessagesOfConsumer(consumer,
|
|
254
|
+
async consumeNatsMessagesOfConsumer(consumer, consumeOptions) {
|
|
255
255
|
if (this.natsMessageIterator) {
|
|
256
256
|
await this.natsMessageIterator.close();
|
|
257
257
|
}
|
|
258
|
-
this.natsMessageIterator = await consumer.consume(
|
|
258
|
+
this.natsMessageIterator = await consumer.consume(consumeOptions);
|
|
259
259
|
for await (const msg of this.natsMessageIterator) {
|
|
260
260
|
try {
|
|
261
261
|
let event;
|
|
@@ -314,13 +314,23 @@ class FlowApplication {
|
|
|
314
314
|
...nats_1.defaultConsumerConfig,
|
|
315
315
|
name: `flow-deployment-${this.context.deploymentId}`,
|
|
316
316
|
filter_subject: `${nats_1.natsFlowsPrefixFlowDeployment}.${this.context.deploymentId}.*`,
|
|
317
|
+
inactive_threshold: 10 * 60 * 1_000_000_000,
|
|
317
318
|
};
|
|
318
319
|
const consumer = await (0, nats_1.getOrCreateConsumer)(this.logger, this._natsConnection, nats_1.FLOWS_STREAM_NAME, consumerOptions.name, consumerOptions);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
const handleNatsStatus = async () => {
|
|
321
|
+
try {
|
|
322
|
+
this.logger.debug('ConsumerService: Reconnected to Nats and re-creating non-durable consumers');
|
|
323
|
+
await (0, nats_1.getOrCreateConsumer)(this.logger, this._natsConnection, nats_1.FLOWS_STREAM_NAME, consumerOptions.name, consumerOptions);
|
|
324
|
+
this.consumeNatsMessagesOfConsumer(consumer, { expires: 10 * 1_000_000_000 });
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
this.logger.error('NATS Status-AsyncIterator is not available, cannot listen. Due to error:');
|
|
328
|
+
this.logger.error(e);
|
|
329
|
+
(0, nats_1.natsEventListener)(this._natsConnection, this.logger, handleNatsStatus);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
(0, nats_1.natsEventListener)(this._natsConnection, this.logger, handleNatsStatus);
|
|
333
|
+
this.consumeNatsMessagesOfConsumer(consumer, { expires: 10 * 1_000_000_000 });
|
|
324
334
|
}
|
|
325
335
|
catch (e) {
|
|
326
336
|
await logErrorAndExit(`Could not set up consumer for deployment messages exchanges: ${e}`);
|
package/dist/FlowLogger.js
CHANGED
|
@@ -36,7 +36,13 @@ class FlowLogger {
|
|
|
36
36
|
}
|
|
37
37
|
publish(message, level, options) {
|
|
38
38
|
if (this.publishEvent) {
|
|
39
|
-
const
|
|
39
|
+
const data = message?.message
|
|
40
|
+
? message
|
|
41
|
+
: {
|
|
42
|
+
...message,
|
|
43
|
+
message: typeof message === 'string' ? message : JSON.stringify(message),
|
|
44
|
+
};
|
|
45
|
+
const event = new FlowEvent_1.FlowEvent(this.metadata, data, `flow.log.${level}`);
|
|
40
46
|
this.publishEvent(event);
|
|
41
47
|
}
|
|
42
48
|
switch (level) {
|
package/dist/nats.js
CHANGED
|
@@ -59,7 +59,6 @@ async function natsEventListener(nc, logger, reconnectHandler) {
|
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
for await (const status of statusAsyncIterator) {
|
|
62
|
-
logger.debug(`[NatsConsumerService] ${status.type}`);
|
|
63
62
|
if (status.type === 'reconnect') {
|
|
64
63
|
reconnectHandler();
|
|
65
64
|
}
|
|
@@ -84,7 +83,7 @@ async function publishNatsEvent(logger, nc, event, subject) {
|
|
|
84
83
|
async function createNatsConnection(config) {
|
|
85
84
|
const servers = config?.servers ?? process.env.NATS_SERVERS?.split(',') ?? [];
|
|
86
85
|
const reconnect = config?.reconnect ?? (process.env.NATS_RECONNECT ?? 'true') === 'true';
|
|
87
|
-
let maxReconnectAttempts = config?.maxReconnectAttempts ?? parseInt(process.env.NATS_MAX_RECONNECT_ATTEMPTS ?? '
|
|
86
|
+
let maxReconnectAttempts = config?.maxReconnectAttempts ?? parseInt(process.env.NATS_MAX_RECONNECT_ATTEMPTS ?? '-1', 10);
|
|
88
87
|
if (isNaN(maxReconnectAttempts)) {
|
|
89
88
|
maxReconnectAttempts = 10;
|
|
90
89
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hahnpro/flow-sdk",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "SDK for building Flow Modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@hahnpro/hpc-api": "2025.
|
|
27
|
+
"@hahnpro/hpc-api": "2025.3.1",
|
|
28
28
|
"@nats-io/jetstream": "3.1.0",
|
|
29
29
|
"@nats-io/nats-core": "3.1.0",
|
|
30
30
|
"@nats-io/transport-node": "3.1.0",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"@types/amqplib": "0.10.7",
|
|
45
45
|
"@types/jest": "30.0.0",
|
|
46
46
|
"@types/lodash": "4.17.20",
|
|
47
|
-
"@types/node": "22.16.
|
|
47
|
+
"@types/node": "22.16.5",
|
|
48
48
|
"class-validator-jsonschema": "5.0.2",
|
|
49
|
-
"jest": "30.0.
|
|
49
|
+
"jest": "30.0.5",
|
|
50
50
|
"typescript": "5.8.3"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|