@hotmeshio/hotmesh 0.29.1 → 0.30.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/README.md +43 -0
- package/build/index.d.ts +2 -1
- package/build/index.js +3 -1
- package/build/modules/enums.d.ts +35 -0
- package/build/modules/enums.js +41 -1
- package/build/modules/errors.d.ts +26 -2
- package/build/modules/errors.js +82 -1
- package/build/modules/utils.d.ts +8 -0
- package/build/modules/utils.js +19 -1
- package/build/package.json +1 -1
- package/build/services/activities/trigger.js +3 -1
- package/build/services/connector/health.d.ts +42 -0
- package/build/services/connector/health.js +100 -0
- package/build/services/connector/index.js +2 -1
- package/build/services/connector/providers/postgres-resilient-client.d.ts +95 -0
- package/build/services/connector/providers/postgres-resilient-client.js +446 -0
- package/build/services/connector/providers/postgres.d.ts +6 -0
- package/build/services/connector/providers/postgres.js +72 -14
- package/build/services/durable/client.js +11 -3
- package/build/services/durable/handle.js +101 -41
- package/build/services/durable/worker.js +12 -4
- package/build/services/engine/completion.js +3 -3
- package/build/services/engine/signal.js +3 -3
- package/build/services/hotmesh/index.js +13 -4
- package/build/services/quorum/index.js +13 -13
- package/build/services/router/consumption/index.d.ts +20 -0
- package/build/services/router/consumption/index.js +177 -7
- package/build/services/store/providers/postgres/kvtransaction.js +8 -1
- package/build/services/store/providers/postgres/postgres.js +2 -2
- package/build/services/stream/index.d.ts +1 -0
- package/build/services/stream/providers/postgres/messages.d.ts +7 -0
- package/build/services/stream/providers/postgres/messages.js +27 -1
- package/build/services/stream/providers/postgres/notifications.d.ts +13 -0
- package/build/services/stream/providers/postgres/notifications.js +89 -2
- package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
- package/build/services/stream/providers/postgres/postgres.js +22 -3
- package/build/services/stream/registry.d.ts +6 -0
- package/build/services/stream/registry.js +11 -2
- package/build/services/sub/providers/postgres/postgres.d.ts +6 -0
- package/build/services/sub/providers/postgres/postgres.js +62 -2
- package/build/services/task/index.js +1 -1
- package/build/services/worker/credentials.js +5 -0
- package/build/services/worker/index.js +5 -5
- package/build/types/index.d.ts +2 -2
- package/build/types/postgres.d.ts +20 -0
- package/build/types/provider.d.ts +28 -0
- package/index.ts +2 -0
- package/package.json +1 -1
|
@@ -89,6 +89,13 @@ class ClientService {
|
|
|
89
89
|
});
|
|
90
90
|
//synchronously cache the promise (before awaiting)
|
|
91
91
|
ClientService.instances.set(connectionNS, hotMeshClient);
|
|
92
|
+
//an init that rejects (database unavailable) is not cached for the
|
|
93
|
+
//life of the process; the next call initializes again
|
|
94
|
+
hotMeshClient.catch(() => {
|
|
95
|
+
if (ClientService.instances.get(connectionNS) === hotMeshClient) {
|
|
96
|
+
ClientService.instances.delete(connectionNS);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
92
99
|
//resolve, activate, and return the client
|
|
93
100
|
const resolvedClient = await hotMeshClient;
|
|
94
101
|
if (!readonly) {
|
|
@@ -385,9 +392,10 @@ class ClientService {
|
|
|
385
392
|
* @private
|
|
386
393
|
*/
|
|
387
394
|
static async shutdown() {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
395
|
+
//a cached init that rejected must not stop the others from stopping
|
|
396
|
+
const instances = Array.from(ClientService.instances.values());
|
|
397
|
+
ClientService.instances.clear();
|
|
398
|
+
await Promise.allSettled(instances.map(async (hotMeshInstance) => (await hotMeshInstance).stop()));
|
|
391
399
|
}
|
|
392
400
|
}
|
|
393
401
|
_a = ClientService;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WorkflowHandleService = void 0;
|
|
4
|
+
const health_1 = require("../connector/health");
|
|
4
5
|
const utils_1 = require("../../modules/utils");
|
|
5
6
|
const exporter_1 = require("./exporter");
|
|
6
7
|
/**
|
|
@@ -243,7 +244,28 @@ class WorkflowHandleService {
|
|
|
243
244
|
async result(config) {
|
|
244
245
|
const topic = `${this.hotMesh.appId}.executed.${this.workflowId}`;
|
|
245
246
|
let isResolved = false;
|
|
246
|
-
return new Promise(async (
|
|
247
|
+
return new Promise(async (rawResolve, rawReject) => {
|
|
248
|
+
//escalating re-checks: the executed event commits before the status
|
|
249
|
+
//decrement, so a job caught mid-close needs a few quick reads
|
|
250
|
+
const RECHECK_DELAYS_MS = [250, 1000, 5000];
|
|
251
|
+
//a restored database connection re-runs the quick re-checks: a
|
|
252
|
+
//completion NOTIFY sent while the subscription's session was being
|
|
253
|
+
//replaced is gone, and waiting out the steady poll is not needed
|
|
254
|
+
const onRestored = () => {
|
|
255
|
+
if (!isResolved) {
|
|
256
|
+
scheduleRechecks();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
health_1.ConnectionHealth.on('restored', onRestored);
|
|
260
|
+
const release = () => health_1.ConnectionHealth.off('restored', onRestored);
|
|
261
|
+
const resolve = (value) => {
|
|
262
|
+
release();
|
|
263
|
+
rawResolve(value);
|
|
264
|
+
};
|
|
265
|
+
const reject = (error) => {
|
|
266
|
+
release();
|
|
267
|
+
rawReject(error);
|
|
268
|
+
};
|
|
247
269
|
/**
|
|
248
270
|
* rejects/resolves the promise based on the `throwOnError`
|
|
249
271
|
* default behavior is to throw if error
|
|
@@ -265,7 +287,16 @@ class WorkflowHandleService {
|
|
|
265
287
|
return safeReject(err);
|
|
266
288
|
}
|
|
267
289
|
else if (!response) {
|
|
268
|
-
|
|
290
|
+
let state;
|
|
291
|
+
try {
|
|
292
|
+
state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
293
|
+
}
|
|
294
|
+
catch (readError) {
|
|
295
|
+
//the read failed (database unavailable): stay pending so the
|
|
296
|
+
//next check settles the result instead of leaving it hanging
|
|
297
|
+
isResolved = false;
|
|
298
|
+
throw readError;
|
|
299
|
+
}
|
|
269
300
|
if (state.data?.done && !state.data?.$error) {
|
|
270
301
|
return resolve(state.data.response);
|
|
271
302
|
}
|
|
@@ -279,37 +310,8 @@ class WorkflowHandleService {
|
|
|
279
310
|
}
|
|
280
311
|
resolve(response);
|
|
281
312
|
};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
285
|
-
if (state?.data?.done && !state.data?.$error) {
|
|
286
|
-
return complete(state.data.response);
|
|
287
|
-
}
|
|
288
|
-
else if (state.data?.$error) {
|
|
289
|
-
return complete(null, state.data.$error);
|
|
290
|
-
}
|
|
291
|
-
else if (state.metadata.err) {
|
|
292
|
-
return complete(null, JSON.parse(state.metadata.err));
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
//subscribe to 'done' topic. Await the registration: the getStatus
|
|
296
|
-
//fallback below only covers completions that land BEFORE it reads.
|
|
297
|
-
//Unawaited, a job that completes after the status read but before
|
|
298
|
-
//the subscription goes active is seen by neither arm and result()
|
|
299
|
-
//never settles — hit reliably when a bulk resolve completes many
|
|
300
|
-
//workflows in the same instant.
|
|
301
|
-
await this.hotMesh.sub(topic, async (_topic, state) => {
|
|
302
|
-
this.hotMesh.unsub(topic);
|
|
303
|
-
if (state.data.done && !state.data?.$error) {
|
|
304
|
-
await complete(state.data?.response);
|
|
305
|
-
}
|
|
306
|
-
else if (state.data?.$error) {
|
|
307
|
-
return complete(null, state.data.$error);
|
|
308
|
-
}
|
|
309
|
-
else if (state.metadata.err) {
|
|
310
|
-
const error = JSON.parse(state.metadata.err);
|
|
311
|
-
return await complete(null, error);
|
|
312
|
-
}
|
|
313
|
+
const unsubscribe = () => (0, utils_1.detach)(this.hotMesh.unsub(topic), this.hotMesh.engine?.logger, 'durable-result-unsub-error', {
|
|
314
|
+
workflowId: this.workflowId,
|
|
313
315
|
});
|
|
314
316
|
//check state in case completed during wiring. One read is not
|
|
315
317
|
//enough: the executed event commits before the status decrement,
|
|
@@ -327,27 +329,85 @@ class WorkflowHandleService {
|
|
|
327
329
|
return true;
|
|
328
330
|
if (status <= 0) {
|
|
329
331
|
await complete();
|
|
330
|
-
|
|
332
|
+
unsubscribe();
|
|
331
333
|
return true;
|
|
332
334
|
}
|
|
333
335
|
return false;
|
|
334
336
|
};
|
|
335
|
-
|
|
337
|
+
//a failed check (database unavailable) is a miss, never the end of
|
|
338
|
+
//the wait: the next scheduled check tries again
|
|
339
|
+
const settle = async () => {
|
|
340
|
+
try {
|
|
341
|
+
return await settleIfComplete();
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
return isResolved;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
function scheduleRechecks() {
|
|
348
|
+
void (async () => {
|
|
349
|
+
for (const delay of RECHECK_DELAYS_MS) {
|
|
350
|
+
await (0, utils_1.sleepFor)(delay);
|
|
351
|
+
if (await settle())
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
})();
|
|
355
|
+
}
|
|
356
|
+
try {
|
|
357
|
+
//more expensive; fetches the entire job, not just the `status`
|
|
358
|
+
if (config?.state) {
|
|
359
|
+
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
360
|
+
if (state?.data?.done && !state.data?.$error) {
|
|
361
|
+
return complete(state.data.response);
|
|
362
|
+
}
|
|
363
|
+
else if (state.data?.$error) {
|
|
364
|
+
return complete(null, state.data.$error);
|
|
365
|
+
}
|
|
366
|
+
else if (state.metadata.err) {
|
|
367
|
+
return complete(null, JSON.parse(state.metadata.err));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
//subscribe to 'done' topic. Await the registration: the getStatus
|
|
371
|
+
//fallback below only covers completions that land BEFORE it reads.
|
|
372
|
+
//Unawaited, a job that completes after the status read but before
|
|
373
|
+
//the subscription goes active is seen by neither arm and result()
|
|
374
|
+
//never settles — hit reliably when a bulk resolve completes many
|
|
375
|
+
//workflows in the same instant.
|
|
376
|
+
await this.hotMesh.sub(topic, async (_topic, state) => {
|
|
377
|
+
unsubscribe();
|
|
378
|
+
if (state.data.done && !state.data?.$error) {
|
|
379
|
+
await complete(state.data?.response);
|
|
380
|
+
}
|
|
381
|
+
else if (state.data?.$error) {
|
|
382
|
+
return complete(null, state.data.$error);
|
|
383
|
+
}
|
|
384
|
+
else if (state.metadata.err) {
|
|
385
|
+
const error = JSON.parse(state.metadata.err);
|
|
386
|
+
return await complete(null, error);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
catch (setupError) {
|
|
391
|
+
//the wait could not be established; the caller sees the error
|
|
392
|
+
if (!isResolved) {
|
|
393
|
+
isResolved = true;
|
|
394
|
+
reject(setupError);
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (!(await settle())) {
|
|
336
399
|
void (async () => {
|
|
337
|
-
const RECHECK_DELAYS_MS = [250, 1000, 5000];
|
|
338
400
|
for (const delay of RECHECK_DELAYS_MS) {
|
|
339
401
|
await (0, utils_1.sleepFor)(delay);
|
|
340
|
-
if (await
|
|
402
|
+
if (await settle())
|
|
341
403
|
return;
|
|
342
404
|
}
|
|
343
405
|
while (!isResolved) {
|
|
344
406
|
await (0, utils_1.sleepFor)(30000);
|
|
345
|
-
if (await
|
|
407
|
+
if (await settle())
|
|
346
408
|
return;
|
|
347
409
|
}
|
|
348
|
-
})()
|
|
349
|
-
//the subscription remains the primary completion arm
|
|
350
|
-
});
|
|
410
|
+
})();
|
|
351
411
|
}
|
|
352
412
|
});
|
|
353
413
|
}
|
|
@@ -486,7 +486,7 @@ class WorkerService {
|
|
|
486
486
|
const worker = new WorkerService();
|
|
487
487
|
worker.activityRunner = await worker.initActivityWorker(config, activityTopic);
|
|
488
488
|
worker.workflowRunner = await worker.initWorkflowWorker(config, taskQueue, workflowFunctionName, workflowTopic, workflowFunction);
|
|
489
|
-
search_1.Search.configureSearchIndex(worker.workflowRunner, config.search);
|
|
489
|
+
(0, utils_1.detach)(search_1.Search.configureSearchIndex(worker.workflowRunner, config.search), worker.workflowRunner?.engine?.logger, 'durable-worker-search-index-error');
|
|
490
490
|
await WorkerService.activateWorkflow(worker.workflowRunner);
|
|
491
491
|
// Fire system.worker.{taskQueue}.started post-init (best-effort).
|
|
492
492
|
if (config.events?.publish) {
|
|
@@ -1070,9 +1070,10 @@ class WorkerService {
|
|
|
1070
1070
|
* @private
|
|
1071
1071
|
*/
|
|
1072
1072
|
static async shutdown() {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1073
|
+
//a cached init that rejected must not stop the others from stopping
|
|
1074
|
+
const instances = Array.from(WorkerService.instances.values());
|
|
1075
|
+
WorkerService.instances.clear();
|
|
1076
|
+
await Promise.allSettled(instances.map(async (hotMeshInstance) => (await hotMeshInstance).stop()));
|
|
1076
1077
|
}
|
|
1077
1078
|
}
|
|
1078
1079
|
_a = WorkerService;
|
|
@@ -1103,6 +1104,13 @@ WorkerService.getHotMesh = async (workflowTopic, config, options) => {
|
|
|
1103
1104
|
},
|
|
1104
1105
|
});
|
|
1105
1106
|
WorkerService.instances.set(targetTopic, hotMeshClient);
|
|
1107
|
+
//an init that rejects (database unavailable) is not cached for the
|
|
1108
|
+
//life of the process; the next call initializes again
|
|
1109
|
+
hotMeshClient.catch(() => {
|
|
1110
|
+
if (WorkerService.instances.get(targetTopic) === hotMeshClient) {
|
|
1111
|
+
WorkerService.instances.delete(targetTopic);
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1106
1114
|
await WorkerService.activateWorkflow(await hotMeshClient);
|
|
1107
1115
|
return hotMeshClient;
|
|
1108
1116
|
};
|
|
@@ -126,8 +126,8 @@ async function runJobCompletionTasks(instance, context, options = {}, transactio
|
|
|
126
126
|
await publishPermanentSubscribers(instance, context, jobOutput, options.emit, transaction);
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
|
-
publishOneTimeSubscribers(instance, context, jobOutput, options.emit);
|
|
130
|
-
publishPermanentSubscribers(instance, context, jobOutput, options.emit);
|
|
129
|
+
(0, utils_1.detach)(publishOneTimeSubscribers(instance, context, jobOutput, options.emit), instance.logger, 'engine-publish-onetime-subscribers-error');
|
|
130
|
+
(0, utils_1.detach)(publishPermanentSubscribers(instance, context, jobOutput, options.emit), instance.logger, 'engine-publish-permanent-subscribers-error');
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
if (!options.emit) {
|
|
@@ -135,7 +135,7 @@ async function runJobCompletionTasks(instance, context, options = {}, transactio
|
|
|
135
135
|
await instance.taskService.registerJobForCleanup(context.metadata.jid, resolveExpires(context, options), options, transaction);
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
|
-
instance.taskService.registerJobForCleanup(context.metadata.jid, resolveExpires(context, options), options);
|
|
138
|
+
(0, utils_1.detach)(instance.taskService.registerJobForCleanup(context.metadata.jid, resolveExpires(context, options), options), instance.logger, 'engine-register-cleanup-error');
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
return msgId;
|
|
@@ -81,7 +81,7 @@ async function signalAll(instance, hookTopic, data, keyResolver, queryFacets = [
|
|
|
81
81
|
keyResolver.scrub || false,
|
|
82
82
|
JSON.stringify(data),
|
|
83
83
|
].join(key_1.VALSEP)));
|
|
84
|
-
instance.subscribe.publish(key_1.KeyType.QUORUM, { type: 'work', originator: instance.guid }, instance.appId);
|
|
84
|
+
(0, utils_1.detach)(instance.subscribe.publish(key_1.KeyType.QUORUM, { type: 'work', originator: instance.guid }, instance.appId), instance.logger, 'engine-signal-work-publish-error');
|
|
85
85
|
}
|
|
86
86
|
return workItems;
|
|
87
87
|
}
|
|
@@ -91,11 +91,11 @@ async function signalAll(instance, hookTopic, data, keyResolver, queryFacets = [
|
|
|
91
91
|
}
|
|
92
92
|
exports.signalAll = signalAll;
|
|
93
93
|
async function processWebHooks(instance, signalFn) {
|
|
94
|
-
instance.taskService.processWebHooks(signalFn);
|
|
94
|
+
(0, utils_1.detach)(instance.taskService.processWebHooks(signalFn), instance.logger, 'engine-process-webhooks-error');
|
|
95
95
|
}
|
|
96
96
|
exports.processWebHooks = processWebHooks;
|
|
97
97
|
async function processTimeHooks(instance, hookTimeFn) {
|
|
98
|
-
instance.taskService.processTimeHooks(hookTimeFn);
|
|
98
|
+
(0, utils_1.detach)(instance.taskService.processTimeHooks(hookTimeFn), instance.logger, 'engine-process-timehooks-error');
|
|
99
99
|
}
|
|
100
100
|
exports.processTimeHooks = processTimeHooks;
|
|
101
101
|
async function throttle(instance, delayInMillis) {
|
|
@@ -28,6 +28,7 @@ const utils_1 = require("../../modules/utils");
|
|
|
28
28
|
const factory_1 = require("../connector/factory");
|
|
29
29
|
const logger_1 = require("../logger");
|
|
30
30
|
const router_1 = require("../router");
|
|
31
|
+
const registry_1 = require("../stream/registry");
|
|
31
32
|
// Submodules
|
|
32
33
|
const Validation = __importStar(require("./validation"));
|
|
33
34
|
const Init = __importStar(require("./init"));
|
|
@@ -193,13 +194,13 @@ class HotMesh {
|
|
|
193
194
|
const quorum = instance.quorum;
|
|
194
195
|
const engineGuid = instance.guid;
|
|
195
196
|
instance.engine.router.setDuressCallback((snapshot) => {
|
|
196
|
-
quorum.pub({
|
|
197
|
+
(0, utils_1.detach)(quorum.pub({
|
|
197
198
|
type: 'duress',
|
|
198
199
|
originator: engineGuid,
|
|
199
200
|
duress_score_ms: snapshot.score_ms,
|
|
200
201
|
throttle_ms: snapshot.throttle_ms,
|
|
201
202
|
level: snapshot.level,
|
|
202
|
-
});
|
|
203
|
+
}), instance.logger, 'hotmesh-duress-publish-error');
|
|
203
204
|
});
|
|
204
205
|
}
|
|
205
206
|
await Init.doWork(instance, config, instance.logger);
|
|
@@ -500,8 +501,16 @@ class HotMesh {
|
|
|
500
501
|
static async stop() {
|
|
501
502
|
if (!this.disconnecting) {
|
|
502
503
|
this.disconnecting = true;
|
|
503
|
-
|
|
504
|
-
|
|
504
|
+
try {
|
|
505
|
+
await router_1.Router.stopConsuming();
|
|
506
|
+
//the stopped consumers are forgotten so a later init in this
|
|
507
|
+
//process starts live ones instead of reusing stopped routers
|
|
508
|
+
registry_1.StreamConsumerRegistry.clear();
|
|
509
|
+
await factory_1.ConnectorService.disconnectAll();
|
|
510
|
+
}
|
|
511
|
+
finally {
|
|
512
|
+
this.disconnecting = false;
|
|
513
|
+
}
|
|
505
514
|
}
|
|
506
515
|
}
|
|
507
516
|
/**
|
|
@@ -37,8 +37,8 @@ class QuorumService {
|
|
|
37
37
|
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId);
|
|
38
38
|
//app-specific quorum subscription (used for pubsub one-time request/response)
|
|
39
39
|
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId, instance.guid);
|
|
40
|
-
instance.engine.processWebHooks();
|
|
41
|
-
instance.engine.processTimeHooks();
|
|
40
|
+
(0, utils_1.detach)(instance.engine.processWebHooks(), logger, 'quorum-process-webhooks-error');
|
|
41
|
+
(0, utils_1.detach)(instance.engine.processTimeHooks(), logger, 'quorum-process-timehooks-error');
|
|
42
42
|
return instance;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -74,7 +74,7 @@ class QuorumService {
|
|
|
74
74
|
self.engine.setCacheMode(message.cache_mode, message.until_version);
|
|
75
75
|
}
|
|
76
76
|
else if (message.type === 'ping') {
|
|
77
|
-
self.sayPong(self.appId, self.guid, message.originator, message.details);
|
|
77
|
+
(0, utils_1.detach)(self.sayPong(self.appId, self.guid, message.originator, message.details), self.logger, 'quorum-pong-error');
|
|
78
78
|
}
|
|
79
79
|
else if (message.type === 'pong' && self.guid === message.originator) {
|
|
80
80
|
self.quorum = self.quorum + 1;
|
|
@@ -83,10 +83,10 @@ class QuorumService {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
else if (message.type === 'throttle') {
|
|
86
|
-
self.engine.throttle(message.throttle);
|
|
86
|
+
(0, utils_1.detach)(self.engine.throttle(message.throttle), self.logger, 'quorum-throttle-error');
|
|
87
87
|
}
|
|
88
88
|
else if (message.type === 'work') {
|
|
89
|
-
self.engine.processWebHooks();
|
|
89
|
+
(0, utils_1.detach)(self.engine.processWebHooks(), self.logger, 'quorum-process-webhooks-error');
|
|
90
90
|
}
|
|
91
91
|
else if (message.type === 'job') {
|
|
92
92
|
let jobOutput = message.job;
|
|
@@ -106,10 +106,10 @@ class QuorumService {
|
|
|
106
106
|
return; // Can't route without job data
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
self.engine.routeToSubscribers(message.topic, jobOutput);
|
|
109
|
+
(0, utils_1.detach)(self.engine.routeToSubscribers(message.topic, jobOutput), self.logger, 'quorum-route-subscribers-error');
|
|
110
110
|
}
|
|
111
111
|
else if (message.type === 'cron') {
|
|
112
|
-
self.engine.processTimeHooks();
|
|
112
|
+
(0, utils_1.detach)(self.engine.processTimeHooks(), self.logger, 'quorum-process-timehooks-error');
|
|
113
113
|
}
|
|
114
114
|
else if (message.type === 'duress') {
|
|
115
115
|
// Apply remote duress signal (skip our own broadcasts)
|
|
@@ -118,7 +118,7 @@ class QuorumService {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
else if (message.type === 'rollcall') {
|
|
121
|
-
self.doRollCall(message);
|
|
121
|
+
(0, utils_1.detach)(self.doRollCall(message), self.logger, 'quorum-rollcall-error');
|
|
122
122
|
}
|
|
123
123
|
//if there are any callbacks, call them
|
|
124
124
|
if (self.callbacks.length > 0) {
|
|
@@ -161,12 +161,12 @@ class QuorumService {
|
|
|
161
161
|
profile.duress_per_type = duressSnapshot.per_type;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
|
|
164
|
+
(0, utils_1.detach)(this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
|
|
165
165
|
type: 'pong',
|
|
166
166
|
guid,
|
|
167
167
|
originator,
|
|
168
168
|
profile,
|
|
169
|
-
}, appId);
|
|
169
|
+
}, appId), this.logger, 'quorum-pong-publish-error');
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* A quorum-wide command to request a quorum count.
|
|
@@ -243,7 +243,7 @@ class QuorumService {
|
|
|
243
243
|
async rollCall(delay = enums_1.HMSH_QUORUM_DELAY_MS) {
|
|
244
244
|
await this.requestQuorum(delay, true);
|
|
245
245
|
const stream_depths = await this.engine.stream.getStreamDepths(this.profiles);
|
|
246
|
-
this.profiles.forEach(
|
|
246
|
+
this.profiles.forEach((profile, index) => {
|
|
247
247
|
//if nothing in the table, the depth will be 0
|
|
248
248
|
//todo: separate table for every worker stream?
|
|
249
249
|
profile.stream_depth = stream_depths?.[index]?.depth ?? 0;
|
|
@@ -270,7 +270,7 @@ class QuorumService {
|
|
|
270
270
|
const q3 = await this.requestQuorum(delay);
|
|
271
271
|
if (q1 && q1 === q2 && q2 === q3) {
|
|
272
272
|
this.logger.info('quorum-rollcall-succeeded', { q1, q2, q3 });
|
|
273
|
-
this.subscribe.publish(hotmesh_1.KeyType.QUORUM, { type: 'activate', cache_mode: 'nocache', until_version: version }, this.appId);
|
|
273
|
+
(0, utils_1.detach)(this.subscribe.publish(hotmesh_1.KeyType.QUORUM, { type: 'activate', cache_mode: 'nocache', until_version: version }, this.appId), this.logger, 'quorum-activate-publish-error');
|
|
274
274
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
275
275
|
await this.store.releaseScoutRole('activate');
|
|
276
276
|
//confirm we received the activation message
|
|
@@ -287,7 +287,7 @@ class QuorumService {
|
|
|
287
287
|
}
|
|
288
288
|
else {
|
|
289
289
|
this.logger.warn('quorum-rollcall-error', { q1, q2, q3, count });
|
|
290
|
-
this.store.releaseScoutRole('activate');
|
|
290
|
+
(0, utils_1.detach)(this.store.releaseScoutRole('activate'), this.logger, 'quorum-release-scout-error');
|
|
291
291
|
if (count < enums_1.HMSH_ACTIVATION_MAX_RETRY) {
|
|
292
292
|
//increase the delay (give the quorum time to respond) and try again
|
|
293
293
|
return await this.activate(version, delay * 2, count + 1);
|
|
@@ -31,6 +31,9 @@ export declare class ConsumptionManager<S extends StreamService<ProviderClient,
|
|
|
31
31
|
private onDuressChange?;
|
|
32
32
|
private messagesSinceLastEval;
|
|
33
33
|
private canExtendReservations;
|
|
34
|
+
private redeliveryWakes;
|
|
35
|
+
private deferredReservations;
|
|
36
|
+
private releaseArmed;
|
|
34
37
|
private adaptiveReservationTimeout;
|
|
35
38
|
private adaptiveBatchSize;
|
|
36
39
|
private lastDepthCheckAt;
|
|
@@ -53,6 +56,23 @@ export declare class ConsumptionManager<S extends StreamService<ProviderClient,
|
|
|
53
56
|
consumeMessages(stream: string, group: string, consumer: string, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<void>;
|
|
54
57
|
private consumeWithNotifications;
|
|
55
58
|
private consumeWithPolling;
|
|
59
|
+
/**
|
|
60
|
+
* Record a message this consumer deferred because the connection was
|
|
61
|
+
* unavailable. The reservation is released as soon as a connection is
|
|
62
|
+
* restored, so the message is redelivered at once; the timed wake below
|
|
63
|
+
* remains the fallback when a release is not possible.
|
|
64
|
+
*/
|
|
65
|
+
private deferForRedelivery;
|
|
66
|
+
private armDeferredRelease;
|
|
67
|
+
private releaseDeferred;
|
|
68
|
+
/**
|
|
69
|
+
* A message left unacked because the connection was unavailable is
|
|
70
|
+
* redelivered once its reservation lapses, but only when a consumer
|
|
71
|
+
* next fetches. Wake the stream's consumers just after the lapse (and
|
|
72
|
+
* twice more, in case the database is still away) instead of waiting
|
|
73
|
+
* for the fallback poller. One schedule per stream at a time.
|
|
74
|
+
*/
|
|
75
|
+
private scheduleRedeliveryWake;
|
|
56
76
|
/**
|
|
57
77
|
* Whether reservation heartbeats are available: the provider must
|
|
58
78
|
* implement extendReservation and advertise the capability.
|