@hotmeshio/hotmesh 0.0.33 → 0.0.34

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "test:hmsh": "NODE_ENV=test jest ./tests/functional/index.test.ts --detectOpenHandles --verbose",
24
24
  "test:compile": "NODE_ENV=test jest ./tests/functional/compile/index.test.ts --detectOpenHandles --forceExit --verbose",
25
25
  "test:cycle": "NODE_ENV=test jest ./tests/functional/cycle/index.test.ts --detectOpenHandles --forceExit --verbose",
26
+ "test:trigger": "NODE_ENV=test jest ./tests/unit/services/activities/trigger.test.ts --detectOpenHandles --forceExit --verbose",
26
27
  "test:connect": "NODE_ENV=test jest ./tests/unit/services/connector/index.test.ts --detectOpenHandles --forceExit --verbose",
27
28
  "test:connect:redis": "NODE_ENV=test jest ./tests/unit/services/connector/clients/redis.test.ts --detectOpenHandles --forceExit --verbose",
28
29
  "test:connect:ioredis": "NODE_ENV=test jest ./tests/unit/services/connector/clients/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
@@ -178,9 +178,8 @@ class ClientService {
178
178
  }
179
179
  }
180
180
  static async shutdown() {
181
- for (const [key, value] of ClientService.instances) {
182
- const hotMesh = await value;
183
- await hotMesh.stop();
181
+ for (const [_, hotMeshInstance] of ClientService.instances) {
182
+ (await hotMeshInstance).stop();
184
183
  }
185
184
  }
186
185
  }
@@ -12,5 +12,10 @@ export declare const Durable: {
12
12
  MeshOS: typeof MeshOSService;
13
13
  Worker: typeof WorkerService;
14
14
  workflow: typeof WorkflowService;
15
+ /**
16
+ * Shutdown everything. All connections, workers, and clients will be closed.
17
+ * Include in your signal handlers to ensure a clean shutdown.
18
+ */
19
+ shutdown(): Promise<void>;
15
20
  };
16
21
  export type { ContextType };
@@ -7,6 +7,7 @@ const meshos_1 = require("./meshos");
7
7
  const search_1 = require("./search");
8
8
  const worker_1 = require("./worker");
9
9
  const workflow_1 = require("./workflow");
10
+ const hotmesh_1 = require("../hotmesh");
10
11
  exports.Durable = {
11
12
  Client: client_1.ClientService,
12
13
  Connection: connection_1.ConnectionService,
@@ -14,4 +15,13 @@ exports.Durable = {
14
15
  MeshOS: meshos_1.MeshOSService,
15
16
  Worker: worker_1.WorkerService,
16
17
  workflow: workflow_1.WorkflowService,
18
+ /**
19
+ * Shutdown everything. All connections, workers, and clients will be closed.
20
+ * Include in your signal handlers to ensure a clean shutdown.
21
+ */
22
+ async shutdown() {
23
+ await client_1.ClientService.shutdown();
24
+ await worker_1.WorkerService.shutdown();
25
+ await hotmesh_1.HotMeshService.stop();
26
+ }
17
27
  };
@@ -8,7 +8,6 @@ const client_1 = require("./client");
8
8
  const search_1 = require("./search");
9
9
  const worker_1 = require("./worker");
10
10
  const workflow_1 = require("./workflow");
11
- const stream_1 = require("../signaler/stream");
12
11
  /**
13
12
  * The base class for running MeshOS workflows.
14
13
  * Extend this class, add your Redis config, and add functions to
@@ -47,9 +46,7 @@ class MeshOSService {
47
46
  * @returns {Promise<void>}
48
47
  */
49
48
  static async stopWorkers() {
50
- await _1.Durable.Client.shutdown();
51
- await _1.Durable.Worker.shutdown();
52
- await stream_1.StreamSignaler.stopConsuming();
49
+ await _1.Durable.shutdown();
53
50
  }
54
51
  /**
55
52
  * Initializes the worker(s). This is a static
@@ -240,9 +240,8 @@ class WorkerService {
240
240
  };
241
241
  }
242
242
  static async shutdown() {
243
- for (const [key, value] of WorkerService.instances) {
244
- const hotMesh = await value;
245
- await hotMesh.stop();
243
+ for (const [_, hotMeshInstance] of WorkerService.instances) {
244
+ (await hotMeshInstance).stop();
246
245
  }
247
246
  }
248
247
  }
@@ -16,6 +16,7 @@ declare class HotMeshService {
16
16
  quorum: QuorumService | null;
17
17
  workers: WorkerService[];
18
18
  logger: ILogger;
19
+ static disconnecting: boolean;
19
20
  verifyAndSetNamespace(namespace?: string): void;
20
21
  verifyAndSetAppId(appId: string): void;
21
22
  static init(config: HotMeshConfig): Promise<HotMeshService>;
@@ -42,7 +43,8 @@ declare class HotMeshService {
42
43
  scrub(jobId: string): Promise<void>;
43
44
  hook(topic: string, data: JobData, status?: StreamStatus, code?: StreamCode): Promise<string>;
44
45
  hookAll(hookTopic: string, data: JobData, query: JobStatsInput, queryFacets?: string[]): Promise<string[]>;
45
- stop(): Promise<void>;
46
+ static stop(): Promise<void>;
47
+ stop(): void;
46
48
  compress(terms: string[]): Promise<boolean>;
47
49
  }
48
50
  export { HotMeshService };
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HotMeshService = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
5
  const key_1 = require("../../modules/key");
6
+ const redis_1 = require("../connector/clients/redis");
7
+ const ioredis_1 = require("../connector/clients/ioredis");
6
8
  const engine_1 = require("../engine");
7
9
  const logger_1 = require("../logger");
8
10
  const stream_1 = require("../signaler/stream");
@@ -128,8 +130,15 @@ class HotMeshService {
128
130
  async hookAll(hookTopic, data, query, queryFacets = []) {
129
131
  return await this.engine?.hookAll(hookTopic, data, query, queryFacets);
130
132
  }
131
- async stop() {
132
- await stream_1.StreamSignaler.stopConsuming();
133
+ static async stop() {
134
+ if (!this.disconnecting) {
135
+ this.disconnecting = true;
136
+ await stream_1.StreamSignaler.stopConsuming();
137
+ await redis_1.RedisConnection.disconnectAll();
138
+ await ioredis_1.RedisConnection.disconnectAll();
139
+ }
140
+ }
141
+ stop() {
133
142
  this.engine?.task.cancelCleanup();
134
143
  }
135
144
  async compress(terms) {
@@ -137,3 +146,4 @@ class HotMeshService {
137
146
  }
138
147
  }
139
148
  exports.HotMeshService = HotMeshService;
149
+ HotMeshService.disconnecting = false;
@@ -220,12 +220,12 @@ class StreamSignaler {
220
220
  for (const instance of [...StreamSignaler.signalers]) {
221
221
  instance.stopConsuming();
222
222
  }
223
+ await (0, utils_1.sleepFor)(BLOCK_TIME_MS);
223
224
  }
224
225
  async stopConsuming() {
225
226
  this.shouldConsume = false;
226
227
  this.logger.info(`stream-consumer-stopping`, this.topic ? { topic: this.topic } : undefined);
227
228
  this.cancelThrottle();
228
- //await sleepFor(BLOCK_TIME_MS);
229
229
  }
230
230
  cancelThrottle() {
231
231
  if (this.currentTimerId !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "test:hmsh": "NODE_ENV=test jest ./tests/functional/index.test.ts --detectOpenHandles --verbose",
24
24
  "test:compile": "NODE_ENV=test jest ./tests/functional/compile/index.test.ts --detectOpenHandles --forceExit --verbose",
25
25
  "test:cycle": "NODE_ENV=test jest ./tests/functional/cycle/index.test.ts --detectOpenHandles --forceExit --verbose",
26
+ "test:trigger": "NODE_ENV=test jest ./tests/unit/services/activities/trigger.test.ts --detectOpenHandles --forceExit --verbose",
26
27
  "test:connect": "NODE_ENV=test jest ./tests/unit/services/connector/index.test.ts --detectOpenHandles --forceExit --verbose",
27
28
  "test:connect:redis": "NODE_ENV=test jest ./tests/unit/services/connector/clients/redis.test.ts --detectOpenHandles --forceExit --verbose",
28
29
  "test:connect:ioredis": "NODE_ENV=test jest ./tests/unit/services/connector/clients/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
@@ -198,9 +198,8 @@ export class ClientService {
198
198
  }
199
199
 
200
200
  static async shutdown(): Promise<void> {
201
- for (const [key, value] of ClientService.instances) {
202
- const hotMesh = await value;
203
- await hotMesh.stop();
201
+ for (const [_, hotMeshInstance] of ClientService.instances) {
202
+ (await hotMeshInstance).stop();
204
203
  }
205
204
  }
206
205
  }
@@ -4,6 +4,7 @@ import { MeshOSService } from './meshos';
4
4
  import { Search } from './search';
5
5
  import { WorkerService } from './worker';
6
6
  import { WorkflowService } from './workflow';
7
+ import { HotMeshService } from '../hotmesh';
7
8
  import { ContextType } from '../../types/durable';
8
9
 
9
10
  export const Durable = {
@@ -13,6 +14,16 @@ export const Durable = {
13
14
  MeshOS: MeshOSService,
14
15
  Worker: WorkerService,
15
16
  workflow: WorkflowService,
17
+
18
+ /**
19
+ * Shutdown everything. All connections, workers, and clients will be closed.
20
+ * Include in your signal handlers to ensure a clean shutdown.
21
+ */
22
+ async shutdown(): Promise<void> {
23
+ await ClientService.shutdown();
24
+ await WorkerService.shutdown();
25
+ await HotMeshService.stop();
26
+ }
16
27
  };
17
28
 
18
29
  export type { ContextType };
@@ -7,7 +7,6 @@ import { WorkflowHandleService } from './handle';
7
7
  import { Search } from './search';
8
8
  import { WorkerService as Worker } from './worker';
9
9
  import { WorkflowService } from './workflow';
10
- import { StreamSignaler } from '../signaler/stream';
11
10
  import {
12
11
  FindOptions,
13
12
  FindWhereOptions,
@@ -135,9 +134,7 @@ export class MeshOSService {
135
134
  * @returns {Promise<void>}
136
135
  */
137
136
  static async stopWorkers(): Promise<void> {
138
- await Durable.Client.shutdown();
139
- await Durable.Worker.shutdown();
140
- await StreamSignaler.stopConsuming();
137
+ await Durable.shutdown();
141
138
  }
142
139
 
143
140
  /**
@@ -291,9 +291,8 @@ export class WorkerService {
291
291
  }
292
292
 
293
293
  static async shutdown(): Promise<void> {
294
- for (const [key, value] of WorkerService.instances) {
295
- const hotMesh = await value;
296
- await hotMesh.stop();
294
+ for (const [_, hotMeshInstance] of WorkerService.instances) {
295
+ (await hotMeshInstance).stop();
297
296
  }
298
297
  }
299
298
  }
@@ -1,5 +1,7 @@
1
1
  import { nanoid } from 'nanoid';
2
2
  import { HMNS } from '../../modules/key';
3
+ import { RedisConnection } from '../connector/clients/redis';
4
+ import { RedisConnection as IORedisConnection } from '../connector/clients/ioredis';
3
5
  import { EngineService } from '../engine';
4
6
  import { LoggerService, ILogger } from '../logger';
5
7
  import { StreamSignaler } from '../signaler/stream';
@@ -32,6 +34,8 @@ class HotMeshService {
32
34
  workers: WorkerService[] = [];
33
35
  logger: ILogger;
34
36
 
37
+ static disconnecting = false;
38
+
35
39
  verifyAndSetNamespace(namespace?: string) {
36
40
  if (!namespace) {
37
41
  this.namespace = HMNS;
@@ -176,8 +180,16 @@ class HotMeshService {
176
180
  return await this.engine?.hookAll(hookTopic, data, query, queryFacets);
177
181
  }
178
182
 
179
- async stop() {
180
- await StreamSignaler.stopConsuming();
183
+ static async stop() {
184
+ if (!this.disconnecting) {
185
+ this.disconnecting = true;
186
+ await StreamSignaler.stopConsuming();
187
+ await RedisConnection.disconnectAll();
188
+ await IORedisConnection.disconnectAll();
189
+ }
190
+ }
191
+
192
+ stop() {
181
193
  this.engine?.task.cancelCleanup();
182
194
  }
183
195
 
@@ -254,13 +254,13 @@ class StreamSignaler {
254
254
  for (const instance of [...StreamSignaler.signalers]) {
255
255
  instance.stopConsuming();
256
256
  }
257
+ await sleepFor(BLOCK_TIME_MS);
257
258
  }
258
259
 
259
260
  async stopConsuming() {
260
261
  this.shouldConsume = false;
261
262
  this.logger.info(`stream-consumer-stopping`, this.topic ? { topic: this.topic } : undefined);
262
263
  this.cancelThrottle();
263
- //await sleepFor(BLOCK_TIME_MS);
264
264
  }
265
265
 
266
266
  cancelThrottle() {