@hotmeshio/hotmesh 0.4.0 → 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/build/modules/enums.d.ts +110 -0
- package/build/modules/enums.js +134 -0
- package/build/modules/errors.d.ts +124 -0
- package/build/modules/errors.js +191 -0
- package/build/modules/key.d.ts +66 -0
- package/build/modules/key.js +190 -0
- package/build/modules/storage.d.ts +3 -0
- package/build/modules/storage.js +5 -0
- package/build/modules/utils.d.ts +119 -0
- package/build/modules/utils.js +374 -0
- package/build/package.json +1 -1
- package/build/services/activities/activity.d.ts +104 -0
- package/build/services/activities/activity.js +549 -0
- package/build/services/activities/await.d.ts +12 -0
- package/build/services/activities/await.js +114 -0
- package/build/services/activities/cycle.d.ts +19 -0
- package/build/services/activities/cycle.js +112 -0
- package/build/services/activities/hook.d.ts +27 -0
- package/build/services/activities/hook.js +168 -0
- package/build/services/activities/index.d.ts +19 -0
- package/build/services/activities/index.js +20 -0
- package/build/services/activities/interrupt.d.ts +16 -0
- package/build/services/activities/interrupt.js +158 -0
- package/build/services/activities/signal.d.ts +20 -0
- package/build/services/activities/signal.js +134 -0
- package/build/services/activities/trigger.d.ts +37 -0
- package/build/services/activities/trigger.js +246 -0
- package/build/services/activities/worker.d.ts +12 -0
- package/build/services/activities/worker.js +106 -0
- package/build/services/collator/index.d.ts +111 -0
- package/build/services/collator/index.js +293 -0
- package/build/services/compiler/deployer.d.ts +40 -0
- package/build/services/compiler/deployer.js +488 -0
- package/build/services/compiler/index.d.ts +32 -0
- package/build/services/compiler/index.js +112 -0
- package/build/services/compiler/validator.d.ts +34 -0
- package/build/services/compiler/validator.js +147 -0
- package/build/services/connector/factory.d.ts +22 -0
- package/build/services/connector/factory.js +99 -0
- package/build/services/connector/index.d.ts +30 -0
- package/build/services/connector/index.js +54 -0
- package/build/services/connector/providers/ioredis.d.ts +9 -0
- package/build/services/connector/providers/ioredis.js +26 -0
- package/build/services/connector/providers/nats.d.ts +9 -0
- package/build/services/connector/providers/nats.js +34 -0
- package/build/services/connector/providers/postgres.d.ts +20 -0
- package/build/services/connector/providers/postgres.js +102 -0
- package/build/services/connector/providers/redis.d.ts +9 -0
- package/build/services/connector/providers/redis.js +38 -0
- package/build/services/engine/index.d.ts +264 -0
- package/build/services/engine/index.js +761 -0
- package/build/services/exporter/index.d.ts +44 -0
- package/build/services/exporter/index.js +126 -0
- package/build/services/hotmesh/index.d.ts +483 -0
- package/build/services/hotmesh/index.js +622 -0
- package/build/services/logger/index.d.ts +16 -0
- package/build/services/logger/index.js +54 -0
- package/build/services/mapper/index.d.ts +28 -0
- package/build/services/mapper/index.js +81 -0
- package/build/services/memflow/client.d.ts +108 -0
- package/build/services/memflow/client.js +372 -0
- package/build/services/memflow/connection.d.ts +23 -0
- package/build/services/memflow/connection.js +33 -0
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/memflow/exporter.d.ts +51 -0
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/memflow/handle.d.ts +90 -0
- package/build/services/memflow/handle.js +176 -0
- package/build/services/memflow/index.d.ts +116 -0
- package/build/services/memflow/index.js +122 -0
- package/build/services/memflow/schemas/factory.d.ts +29 -0
- package/build/services/memflow/schemas/factory.js +2492 -0
- package/build/services/memflow/search.d.ts +142 -0
- package/build/services/memflow/search.js +320 -0
- package/build/services/memflow/worker.d.ts +124 -0
- package/build/services/memflow/worker.js +514 -0
- package/build/services/memflow/workflow/all.d.ts +7 -0
- package/build/services/memflow/workflow/all.js +15 -0
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/context.d.ts +6 -0
- package/build/services/memflow/workflow/context.js +45 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/memflow/workflow/didRun.d.ts +7 -0
- package/build/services/memflow/workflow/didRun.js +22 -0
- package/build/services/memflow/workflow/emit.d.ts +11 -0
- package/build/services/memflow/workflow/emit.js +29 -0
- package/build/services/memflow/workflow/enrich.d.ts +9 -0
- package/build/services/memflow/workflow/enrich.js +17 -0
- package/build/services/memflow/workflow/execChild.d.ts +18 -0
- package/build/services/memflow/workflow/execChild.js +102 -0
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/memflow/workflow/hook.d.ts +9 -0
- package/build/services/memflow/workflow/hook.js +56 -0
- package/build/services/memflow/workflow/index.d.ts +74 -0
- package/build/services/memflow/workflow/index.js +87 -0
- package/build/services/memflow/workflow/interrupt.d.ts +9 -0
- package/build/services/memflow/workflow/interrupt.js +24 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
- package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
- package/build/services/memflow/workflow/proxyActivities.js +97 -0
- package/build/services/memflow/workflow/random.d.ts +6 -0
- package/build/services/memflow/workflow/random.js +16 -0
- package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
- package/build/services/memflow/workflow/searchMethods.js +25 -0
- package/build/services/memflow/workflow/signal.d.ts +7 -0
- package/build/services/memflow/workflow/signal.js +28 -0
- package/build/services/memflow/workflow/sleepFor.d.ts +8 -0
- package/build/services/memflow/workflow/sleepFor.js +35 -0
- package/build/services/memflow/workflow/trace.d.ts +14 -0
- package/build/services/memflow/workflow/trace.js +33 -0
- package/build/services/memflow/workflow/waitFor.d.ts +8 -0
- package/build/services/memflow/workflow/waitFor.js +35 -0
- package/build/services/meshcall/index.d.ts +194 -0
- package/build/services/meshcall/index.js +452 -0
- package/build/services/meshcall/schemas/factory.d.ts +9 -0
- package/build/services/meshcall/schemas/factory.js +189 -0
- package/build/services/meshdata/index.d.ts +795 -0
- package/build/services/meshdata/index.js +1235 -0
- package/build/services/meshos/index.d.ts +293 -0
- package/build/services/meshos/index.js +547 -0
- package/build/services/pipe/functions/array.d.ts +17 -0
- package/build/services/pipe/functions/array.js +74 -0
- package/build/services/pipe/functions/bitwise.d.ts +9 -0
- package/build/services/pipe/functions/bitwise.js +24 -0
- package/build/services/pipe/functions/conditional.d.ts +13 -0
- package/build/services/pipe/functions/conditional.js +36 -0
- package/build/services/pipe/functions/cron.d.ts +12 -0
- package/build/services/pipe/functions/cron.js +40 -0
- package/build/services/pipe/functions/date.d.ts +58 -0
- package/build/services/pipe/functions/date.js +171 -0
- package/build/services/pipe/functions/index.d.ts +29 -0
- package/build/services/pipe/functions/index.js +30 -0
- package/build/services/pipe/functions/json.d.ts +5 -0
- package/build/services/pipe/functions/json.js +12 -0
- package/build/services/pipe/functions/logical.d.ts +5 -0
- package/build/services/pipe/functions/logical.js +12 -0
- package/build/services/pipe/functions/math.d.ts +42 -0
- package/build/services/pipe/functions/math.js +184 -0
- package/build/services/pipe/functions/number.d.ts +21 -0
- package/build/services/pipe/functions/number.js +60 -0
- package/build/services/pipe/functions/object.d.ts +25 -0
- package/build/services/pipe/functions/object.js +81 -0
- package/build/services/pipe/functions/string.d.ts +23 -0
- package/build/services/pipe/functions/string.js +69 -0
- package/build/services/pipe/functions/symbol.d.ts +12 -0
- package/build/services/pipe/functions/symbol.js +33 -0
- package/build/services/pipe/functions/unary.d.ts +7 -0
- package/build/services/pipe/functions/unary.js +18 -0
- package/build/services/pipe/index.d.ts +48 -0
- package/build/services/pipe/index.js +242 -0
- package/build/services/quorum/index.d.ts +90 -0
- package/build/services/quorum/index.js +263 -0
- package/build/services/reporter/index.d.ts +50 -0
- package/build/services/reporter/index.js +348 -0
- 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 +57 -0
- package/build/services/router/index.js +121 -0
- 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/factory.d.ts +7 -0
- package/build/services/search/factory.js +24 -0
- package/build/services/search/index.d.ts +23 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/postgres/postgres.d.ts +25 -0
- package/build/services/search/providers/postgres/postgres.js +149 -0
- package/build/services/search/providers/redis/ioredis.d.ts +19 -0
- package/build/services/search/providers/redis/ioredis.js +121 -0
- package/build/services/search/providers/redis/redis.d.ts +19 -0
- package/build/services/search/providers/redis/redis.js +134 -0
- package/build/services/serializer/index.d.ts +42 -0
- package/build/services/serializer/index.js +282 -0
- package/build/services/store/cache.d.ts +67 -0
- package/build/services/store/cache.js +128 -0
- package/build/services/store/factory.d.ts +8 -0
- package/build/services/store/factory.js +24 -0
- package/build/services/store/index.d.ts +89 -0
- package/build/services/store/index.js +9 -0
- package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
- package/build/services/store/providers/postgres/kvsql.js +198 -0
- package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtables.js +441 -0
- package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
- package/build/services/store/providers/postgres/kvtransaction.js +248 -0
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
- package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
- package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
- package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
- package/build/services/store/providers/postgres/postgres.d.ts +145 -0
- package/build/services/store/providers/postgres/postgres.js +1036 -0
- package/build/services/store/providers/redis/_base.d.ts +137 -0
- package/build/services/store/providers/redis/_base.js +980 -0
- package/build/services/store/providers/redis/ioredis.d.ts +20 -0
- package/build/services/store/providers/redis/ioredis.js +180 -0
- package/build/services/store/providers/redis/redis.d.ts +18 -0
- package/build/services/store/providers/redis/redis.js +199 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +2 -0
- package/build/services/stream/factory.d.ts +8 -0
- package/build/services/stream/factory.js +37 -0
- package/build/services/stream/index.d.ts +69 -0
- package/build/services/stream/index.js +11 -0
- package/build/services/stream/providers/nats/nats.d.ts +60 -0
- package/build/services/stream/providers/nats/nats.js +225 -0
- package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -0
- package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -0
- package/build/services/stream/providers/redis/redis.d.ts +61 -0
- package/build/services/stream/providers/redis/redis.js +305 -0
- package/build/services/stream/providers/stream-initializable.d.ts +4 -0
- package/build/services/stream/providers/stream-initializable.js +2 -0
- package/build/services/sub/factory.d.ts +7 -0
- package/build/services/sub/factory.js +29 -0
- package/build/services/sub/index.d.ts +22 -0
- package/build/services/sub/index.js +10 -0
- package/build/services/sub/providers/nats/nats.d.ts +19 -0
- package/build/services/sub/providers/nats/nats.js +105 -0
- package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
- package/build/services/sub/providers/postgres/postgres.js +92 -0
- package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
- package/build/services/sub/providers/redis/ioredis.js +81 -0
- package/build/services/sub/providers/redis/redis.d.ts +17 -0
- package/build/services/sub/providers/redis/redis.js +72 -0
- package/build/services/task/index.d.ts +36 -0
- package/build/services/task/index.js +206 -0
- package/build/services/telemetry/index.d.ts +52 -0
- package/build/services/telemetry/index.js +306 -0
- package/build/services/worker/index.d.ts +77 -0
- package/build/services/worker/index.js +197 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/typedoc.json +0 -47
- 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/memflow.ts +0 -645
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -114
- 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 -231
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EngineService } from '../engine';
|
|
3
|
+
import { ILogger } from '../logger';
|
|
4
|
+
import { StoreService } from '../store';
|
|
5
|
+
import { SubService } from '../sub';
|
|
6
|
+
import { CacheMode } from '../../types/cache';
|
|
7
|
+
import { HotMeshConfig } from '../../types/hotmesh';
|
|
8
|
+
import { ProviderClient, ProviderTransaction } from '../../types/provider';
|
|
9
|
+
import { QuorumMessage, QuorumMessageCallback, QuorumProfile, RollCallMessage, SubscriptionCallback } from '../../types/quorum';
|
|
10
|
+
declare class QuorumService {
|
|
11
|
+
namespace: string;
|
|
12
|
+
appId: string;
|
|
13
|
+
guid: string;
|
|
14
|
+
engine: EngineService;
|
|
15
|
+
profiles: QuorumProfile[];
|
|
16
|
+
store: StoreService<ProviderClient, ProviderTransaction> | null;
|
|
17
|
+
subscribe: SubService<ProviderClient> | null;
|
|
18
|
+
logger: ILogger;
|
|
19
|
+
cacheMode: CacheMode;
|
|
20
|
+
untilVersion: string | null;
|
|
21
|
+
quorum: number | null;
|
|
22
|
+
callbacks: QuorumMessageCallback[];
|
|
23
|
+
rollCallInterval: NodeJS.Timeout;
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
constructor();
|
|
28
|
+
/**
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
static init(namespace: string, appId: string, guid: string, config: HotMeshConfig, engine: EngineService, logger: ILogger): Promise<QuorumService>;
|
|
32
|
+
/**
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
verifyQuorumFields(config: HotMeshConfig): void;
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
initStoreChannel(store: ProviderClient): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
initSubChannel(sub: ProviderClient, store: ProviderClient): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
subscriptionHandler(): SubscriptionCallback;
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
sayPong(appId: string, guid: string, originator: string, details?: boolean): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* A quorum-wide command to request a quorum count.
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
requestQuorum(delay?: number, details?: boolean): Promise<number>;
|
|
57
|
+
/**
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
doRollCall(message: RollCallMessage): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
cancelRollCall(): void;
|
|
65
|
+
/**
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
stop(): void;
|
|
69
|
+
/**
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
pub(quorumMessage: QuorumMessage): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
sub(callback: QuorumMessageCallback): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
unsub(callback: QuorumMessageCallback): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
rollCall(delay?: number): Promise<QuorumProfile[]>;
|
|
85
|
+
/**
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
activate(version: string, delay?: number, count?: number): Promise<boolean>;
|
|
89
|
+
}
|
|
90
|
+
export { QuorumService };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuorumService = void 0;
|
|
4
|
+
const enums_1 = require("../../modules/enums");
|
|
5
|
+
const utils_1 = require("../../modules/utils");
|
|
6
|
+
const compiler_1 = require("../compiler");
|
|
7
|
+
const hotmesh_1 = require("../../types/hotmesh");
|
|
8
|
+
const factory_1 = require("../sub/factory");
|
|
9
|
+
const factory_2 = require("../store/factory");
|
|
10
|
+
class QuorumService {
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
constructor() {
|
|
15
|
+
this.profiles = [];
|
|
16
|
+
this.cacheMode = 'cache';
|
|
17
|
+
this.untilVersion = null;
|
|
18
|
+
this.quorum = null;
|
|
19
|
+
this.callbacks = [];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
static async init(namespace, appId, guid, config, engine, logger) {
|
|
25
|
+
if (config.engine) {
|
|
26
|
+
const instance = new QuorumService();
|
|
27
|
+
instance.verifyQuorumFields(config);
|
|
28
|
+
instance.namespace = namespace;
|
|
29
|
+
instance.appId = appId;
|
|
30
|
+
instance.guid = guid;
|
|
31
|
+
instance.logger = logger;
|
|
32
|
+
instance.engine = engine;
|
|
33
|
+
await instance.initStoreChannel(config.engine.store);
|
|
34
|
+
await instance.initSubChannel(config.engine.sub, config.engine.pub ?? config.engine.store);
|
|
35
|
+
//general quorum subscription
|
|
36
|
+
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId);
|
|
37
|
+
//app-specific quorum subscription (used for pubsub one-time request/response)
|
|
38
|
+
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId, instance.guid);
|
|
39
|
+
instance.engine.processWebHooks();
|
|
40
|
+
instance.engine.processTimeHooks();
|
|
41
|
+
return instance;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
verifyQuorumFields(config) {
|
|
48
|
+
if (!(0, utils_1.identifyProvider)(config.engine.store) ||
|
|
49
|
+
!(0, utils_1.identifyProvider)(config.engine.sub)) {
|
|
50
|
+
throw new Error('quorum config must include `store` and `sub` fields.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
async initStoreChannel(store) {
|
|
57
|
+
this.store = await factory_2.StoreServiceFactory.init(store, this.namespace, this.appId, this.logger);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
async initSubChannel(sub, store) {
|
|
63
|
+
this.subscribe = await factory_1.SubServiceFactory.init(sub, store, this.namespace, this.appId, this.guid, this.logger);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
subscriptionHandler() {
|
|
69
|
+
const self = this;
|
|
70
|
+
return async (topic, message) => {
|
|
71
|
+
self.logger.debug('quorum-event-received', { topic, type: message.type });
|
|
72
|
+
if (message.type === 'activate') {
|
|
73
|
+
self.engine.setCacheMode(message.cache_mode, message.until_version);
|
|
74
|
+
}
|
|
75
|
+
else if (message.type === 'ping') {
|
|
76
|
+
self.sayPong(self.appId, self.guid, message.originator, message.details);
|
|
77
|
+
}
|
|
78
|
+
else if (message.type === 'pong' && self.guid === message.originator) {
|
|
79
|
+
self.quorum = self.quorum + 1;
|
|
80
|
+
if (message.profile) {
|
|
81
|
+
self.profiles.push(message.profile);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (message.type === 'throttle') {
|
|
85
|
+
self.engine.throttle(message.throttle);
|
|
86
|
+
}
|
|
87
|
+
else if (message.type === 'work') {
|
|
88
|
+
self.engine.processWebHooks();
|
|
89
|
+
}
|
|
90
|
+
else if (message.type === 'job') {
|
|
91
|
+
self.engine.routeToSubscribers(message.topic, message.job);
|
|
92
|
+
}
|
|
93
|
+
else if (message.type === 'cron') {
|
|
94
|
+
self.engine.processTimeHooks();
|
|
95
|
+
}
|
|
96
|
+
else if (message.type === 'rollcall') {
|
|
97
|
+
self.doRollCall(message);
|
|
98
|
+
}
|
|
99
|
+
//if there are any callbacks, call them
|
|
100
|
+
if (self.callbacks.length > 0) {
|
|
101
|
+
self.callbacks.forEach((cb) => cb(topic, message));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
async sayPong(appId, guid, originator, details = false) {
|
|
109
|
+
let profile;
|
|
110
|
+
if (details) {
|
|
111
|
+
const stream = this.engine.store.mintKey(hotmesh_1.KeyType.STREAMS, {
|
|
112
|
+
appId: this.appId,
|
|
113
|
+
});
|
|
114
|
+
profile = {
|
|
115
|
+
engine_id: this.guid,
|
|
116
|
+
namespace: this.namespace,
|
|
117
|
+
app_id: this.appId,
|
|
118
|
+
stream,
|
|
119
|
+
counts: this.engine.router.counts,
|
|
120
|
+
timestamp: (0, utils_1.formatISODate)(new Date()),
|
|
121
|
+
inited: this.engine.inited,
|
|
122
|
+
throttle: this.engine.router.throttle,
|
|
123
|
+
reclaimDelay: this.engine.router.reclaimDelay,
|
|
124
|
+
reclaimCount: this.engine.router.reclaimCount,
|
|
125
|
+
system: await (0, utils_1.getSystemHealth)(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
|
|
129
|
+
type: 'pong',
|
|
130
|
+
guid,
|
|
131
|
+
originator,
|
|
132
|
+
profile,
|
|
133
|
+
}, appId);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A quorum-wide command to request a quorum count.
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
async requestQuorum(delay = enums_1.HMSH_QUORUM_DELAY_MS, details = false) {
|
|
140
|
+
const quorum = this.quorum;
|
|
141
|
+
this.quorum = 0;
|
|
142
|
+
this.profiles.length = 0;
|
|
143
|
+
await this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
|
|
144
|
+
type: 'ping',
|
|
145
|
+
originator: this.guid,
|
|
146
|
+
details,
|
|
147
|
+
}, this.appId);
|
|
148
|
+
await (0, utils_1.sleepFor)(delay);
|
|
149
|
+
return quorum;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
async doRollCall(message) {
|
|
155
|
+
let iteration = 0;
|
|
156
|
+
const max = !isNaN(message.max) ? message.max : enums_1.HMSH_QUORUM_ROLLCALL_CYCLES;
|
|
157
|
+
if (this.rollCallInterval)
|
|
158
|
+
clearTimeout(this.rollCallInterval);
|
|
159
|
+
const base = message.interval / 2;
|
|
160
|
+
const amount = base + Math.ceil(Math.random() * base);
|
|
161
|
+
do {
|
|
162
|
+
await (0, utils_1.sleepFor)(Math.ceil(Math.random() * 1000));
|
|
163
|
+
await this.sayPong(this.appId, this.guid, null, true);
|
|
164
|
+
if (!message.interval)
|
|
165
|
+
return;
|
|
166
|
+
const { promise, timerId } = (0, utils_1.XSleepFor)(amount * 1000);
|
|
167
|
+
this.rollCallInterval = timerId;
|
|
168
|
+
await promise;
|
|
169
|
+
} while (this.rollCallInterval && iteration++ < max - 1);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
cancelRollCall() {
|
|
175
|
+
if (this.rollCallInterval) {
|
|
176
|
+
clearTimeout(this.rollCallInterval);
|
|
177
|
+
delete this.rollCallInterval;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
stop() {
|
|
184
|
+
this.cancelRollCall();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @private
|
|
188
|
+
*/
|
|
189
|
+
async pub(quorumMessage) {
|
|
190
|
+
return await this.subscribe.publish(hotmesh_1.KeyType.QUORUM, quorumMessage, this.appId, quorumMessage.topic || quorumMessage.guid);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
async sub(callback) {
|
|
196
|
+
this.callbacks.push(callback);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
async unsub(callback) {
|
|
202
|
+
this.callbacks = this.callbacks.filter((cb) => cb !== callback);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @private
|
|
206
|
+
*/
|
|
207
|
+
async rollCall(delay = enums_1.HMSH_QUORUM_DELAY_MS) {
|
|
208
|
+
await this.requestQuorum(delay, true);
|
|
209
|
+
const stream_depths = await this.engine.stream.getStreamDepths(this.profiles);
|
|
210
|
+
this.profiles.forEach(async (profile, index) => {
|
|
211
|
+
//if nothing in the table, the depth will be 0
|
|
212
|
+
//todo: separate table for every worker stream?
|
|
213
|
+
profile.stream_depth = stream_depths?.[index]?.depth ?? 0;
|
|
214
|
+
});
|
|
215
|
+
return this.profiles;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
async activate(version, delay = enums_1.HMSH_QUORUM_DELAY_MS, count = 0) {
|
|
221
|
+
version = version.toString();
|
|
222
|
+
const canActivate = await this.store.reserveScoutRole('activate', Math.ceil(delay * 6 / 1000) + 1);
|
|
223
|
+
if (!canActivate) {
|
|
224
|
+
//another engine is already activating the app version
|
|
225
|
+
this.logger.debug('quorum-activation-awaiting', { version });
|
|
226
|
+
await (0, utils_1.sleepFor)(delay * 6);
|
|
227
|
+
const app = await this.store.getApp(this.appId, true);
|
|
228
|
+
return app?.active == true && app?.version === version;
|
|
229
|
+
}
|
|
230
|
+
const config = await this.engine.getVID();
|
|
231
|
+
await this.requestQuorum(delay);
|
|
232
|
+
const q1 = await this.requestQuorum(delay);
|
|
233
|
+
const q2 = await this.requestQuorum(delay);
|
|
234
|
+
const q3 = await this.requestQuorum(delay);
|
|
235
|
+
if (q1 && q1 === q2 && q2 === q3) {
|
|
236
|
+
this.logger.info('quorum-rollcall-succeeded', { q1, q2, q3 });
|
|
237
|
+
this.subscribe.publish(hotmesh_1.KeyType.QUORUM, { type: 'activate', cache_mode: 'nocache', until_version: version }, this.appId);
|
|
238
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
239
|
+
await this.store.releaseScoutRole('activate');
|
|
240
|
+
//confirm we received the activation message
|
|
241
|
+
if (this.engine.untilVersion === version) {
|
|
242
|
+
this.logger.info('quorum-activation-succeeded', { version });
|
|
243
|
+
const { id } = config;
|
|
244
|
+
const compiler = new compiler_1.CompilerService(this.store, this.engine.stream, this.logger);
|
|
245
|
+
return await compiler.activate(id, version);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this.logger.error('quorum-activation-error', { version });
|
|
249
|
+
throw new Error(`UntilVersion Not Received. Version ${version} not activated`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this.logger.warn('quorum-rollcall-error', { q1, q2, q3, count });
|
|
254
|
+
this.store.releaseScoutRole('activate');
|
|
255
|
+
if (count < enums_1.HMSH_ACTIVATION_MAX_RETRY) {
|
|
256
|
+
//increase the delay (give the quorum time to respond) and try again
|
|
257
|
+
return await this.activate(version, delay * 2, count + 1);
|
|
258
|
+
}
|
|
259
|
+
throw new Error(`Quorum not reached. Version ${version} not activated.`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.QuorumService = QuorumService;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ILogger } from '../logger';
|
|
2
|
+
import { StoreService } from '../store';
|
|
3
|
+
import { TriggerActivity } from '../../types/activity';
|
|
4
|
+
import { AppVID } from '../../types/app';
|
|
5
|
+
import { ProviderClient, ProviderTransaction } from '../../types/provider';
|
|
6
|
+
import { JobState } from '../../types/job';
|
|
7
|
+
import { GetStatsOptions, StatsResponse, IdsResponse, StatsType, StatType } from '../../types/stats';
|
|
8
|
+
declare class ReporterService {
|
|
9
|
+
private appVersion;
|
|
10
|
+
private logger;
|
|
11
|
+
private store;
|
|
12
|
+
static DEFAULT_GRANULARITY: string;
|
|
13
|
+
constructor(appVersion: AppVID, store: StoreService<ProviderClient, ProviderTransaction>, logger: ILogger);
|
|
14
|
+
getStats(options: GetStatsOptions): Promise<StatsResponse>;
|
|
15
|
+
private validateOptions;
|
|
16
|
+
private generateDateTimeSets;
|
|
17
|
+
private convertRangeToMinutes;
|
|
18
|
+
private buildRedisKey;
|
|
19
|
+
private aggregateData;
|
|
20
|
+
private buildStatsResponse;
|
|
21
|
+
private handleSegments;
|
|
22
|
+
private isoTimestampFromKeyTimestamp;
|
|
23
|
+
getIds(options: GetStatsOptions, facets: string[], idRange?: [number, number]): Promise<IdsResponse>;
|
|
24
|
+
private buildIdsResponse;
|
|
25
|
+
private buildTimeSegments;
|
|
26
|
+
getUniqueFacets(data: StatsResponse): string[];
|
|
27
|
+
getTargetForKey(key: string): string;
|
|
28
|
+
getTargetForTime(key: string): string;
|
|
29
|
+
getWorkItems(options: GetStatsOptions, facets: string[]): Promise<string[]>;
|
|
30
|
+
private buildWorkerLists;
|
|
31
|
+
/**
|
|
32
|
+
* called by `trigger` activity to generate the stats that should
|
|
33
|
+
* be saved to the database. doesn't actually save the stats, but
|
|
34
|
+
* just generates the info that should be saved
|
|
35
|
+
*/
|
|
36
|
+
resolveTriggerStatistics({ stats: statsConfig }: TriggerActivity, context: JobState): StatsType;
|
|
37
|
+
isGeneralMetric(metric: string): boolean;
|
|
38
|
+
isMedianMetric(metric: string): boolean;
|
|
39
|
+
isIndexMetric(metric: string): boolean;
|
|
40
|
+
static isGeneralMetric(metric: string): boolean;
|
|
41
|
+
static isMedianMetric(metric: string): boolean;
|
|
42
|
+
static isIndexMetric(metric: string): boolean;
|
|
43
|
+
resolveMetric({ metric, target }: {
|
|
44
|
+
metric: any;
|
|
45
|
+
target: any;
|
|
46
|
+
}, context: JobState): StatType;
|
|
47
|
+
isCardinalMetric(metric: string): boolean;
|
|
48
|
+
resolveTarget(metric: string, target: string, resolvedValue: string): string;
|
|
49
|
+
}
|
|
50
|
+
export { ReporterService };
|