@hotmeshio/hotmesh 0.1.1 → 0.1.3

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 CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  HotMesh transforms Redis into an Orchestration Engine.
5
5
 
6
- *Write functions in your own preferred style, and let Redis govern their execution, reliably and durably.*
6
+ *Write functions in your own style, and let Redis govern their execution, reliably and durably.*
7
7
 
8
8
  ## Install
9
9
  [![npm version](https://badge.fury.io/js/%40hotmeshio%2Fhotmesh.svg)](https://badge.fury.io/js/%40hotmeshio%2Fhotmesh)
@@ -13,7 +13,7 @@ npm install @hotmeshio/hotmesh
13
13
  ```
14
14
 
15
15
  ## Understanding HotMesh
16
- HotMesh inverts the relationship to Redis: those functions that once used Redis as a cache, are instead *cached and governed* by Redis. Consider the following. It's a typical microservices network, with a tangled mess of services and functions. There's important business logic in there (functions *A*, *B* and *C* are critical!), but they're hard to find and access.
16
+ HotMesh inverts the relationship to Redis: those functions that once used Redis as a cache, are instead *cached and governed* by Redis. Consider the following. It's a typical microservices network, with a tangled mess of services and functions. There's important business logic in there (functions *A*, *B* and *C* are critical), but it's hard to find and access.
17
17
 
18
18
  <img src="./docs/img/operational_data_layer.png" alt="A Tangled Microservices Network with 3 valuable functions buried within" style="max-width:100%;width:600px;">
19
19
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -112,7 +112,7 @@ class Activity {
112
112
  stack: error.stack,
113
113
  name: error.name,
114
114
  });
115
- telemetry && telemetry.setActivityError(error.message);
115
+ telemetry?.setActivityError(error.message);
116
116
  throw error;
117
117
  }
118
118
  finally {
@@ -58,7 +58,7 @@ class Await extends activity_1.Activity {
58
58
  else {
59
59
  this.logger.error('await-process-error', { ...error });
60
60
  }
61
- telemetry.setActivityError(error.message);
61
+ telemetry?.setActivityError(error.message);
62
62
  throw error;
63
63
  }
64
64
  finally {
@@ -58,7 +58,7 @@ class Cycle extends activity_1.Activity {
58
58
  else {
59
59
  this.logger.error('cycle-process-error', { ...error });
60
60
  }
61
- telemetry.setActivityError(error.message);
61
+ telemetry?.setActivityError(error.message);
62
62
  throw error;
63
63
  }
64
64
  finally {
@@ -53,7 +53,7 @@ class Hook extends activity_1.Activity {
53
53
  else {
54
54
  this.logger.error('hook-process-error', { ...error });
55
55
  }
56
- telemetry.setActivityError(error.message);
56
+ telemetry?.setActivityError(error.message);
57
57
  throw error;
58
58
  }
59
59
  finally {
@@ -45,7 +45,7 @@ class Interrupt extends activity_1.Activity {
45
45
  else {
46
46
  this.logger.error('interrupt-process-error', { ...error });
47
47
  }
48
- telemetry.setActivityError(error.message);
48
+ telemetry?.setActivityError(error.message);
49
49
  throw error;
50
50
  }
51
51
  finally {
@@ -66,7 +66,7 @@ class Signal extends activity_1.Activity {
66
66
  else {
67
67
  this.logger.error('signal-process-error', { ...error });
68
68
  }
69
- telemetry.setActivityError(error.message);
69
+ telemetry?.setActivityError(error.message);
70
70
  throw error;
71
71
  }
72
72
  finally {
@@ -56,7 +56,7 @@ class Trigger extends activity_1.Activity {
56
56
  else {
57
57
  this.logger.error('trigger-process-error', { ...error });
58
58
  }
59
- telemetry.setActivityError(error.message);
59
+ telemetry?.setActivityError(error.message);
60
60
  throw error;
61
61
  }
62
62
  finally {
@@ -57,7 +57,7 @@ class Worker extends activity_1.Activity {
57
57
  else {
58
58
  this.logger.error('worker-process-error', { ...error });
59
59
  }
60
- telemetry.setActivityError(error.message);
60
+ telemetry?.setActivityError(error.message);
61
61
  throw error;
62
62
  }
63
63
  finally {
@@ -15,9 +15,9 @@ declare class IORedisStoreService extends StoreService<RedisClientType, RedisMul
15
15
  constructor(redisClient: RedisClientType);
16
16
  /**
17
17
  * When in cluster mode, the getMulti wrapper only
18
- * sends commands to the same node/shard.
19
- * All other commands are sent simultaneously
20
- * using Promise.all and are then collated
18
+ * sends commands to the same node/shard if they share a key.
19
+ * All other commands are sent simultaneouslyusing Promise.all
20
+ * and are then collated
21
21
  */
22
22
  getMulti(): RedisMultiType;
23
23
  exec(...args: any[]): Promise<string | string[] | string[][]>;
@@ -3,19 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IORedisStoreService = void 0;
4
4
  const key_1 = require("../../../modules/key");
5
5
  const index_1 = require("../index");
6
+ const enums_1 = require("../../../modules/enums");
6
7
  class IORedisStoreService extends index_1.StoreService {
7
8
  constructor(redisClient) {
8
9
  super(redisClient);
9
10
  }
10
11
  /**
11
12
  * When in cluster mode, the getMulti wrapper only
12
- * sends commands to the same node/shard.
13
- * All other commands are sent simultaneously
14
- * using Promise.all and are then collated
13
+ * sends commands to the same node/shard if they share a key.
14
+ * All other commands are sent simultaneouslyusing Promise.all
15
+ * and are then collated
15
16
  */
16
17
  getMulti() {
17
18
  const my = this;
18
- if (process.env.HMSH_IS_CLUSTER === 'true') {
19
+ if (enums_1.HMSH_IS_CLUSTER) {
19
20
  const commands = [];
20
21
  const addCommand = (command, args) => {
21
22
  commands.push({ command, args });
@@ -28,12 +29,14 @@ class IORedisStoreService extends index_1.StoreService {
28
29
  async exec() {
29
30
  if (commands.length === 0)
30
31
  return [];
31
- const sameCommand = commands.every(cmd => cmd.command === commands[0].command);
32
- if (sameCommand) {
32
+ const sameKey = commands.every(cmd => {
33
+ return cmd.args[0] === commands[0].args[0];
34
+ });
35
+ if (sameKey) {
33
36
  const multi = my.redisClient.multi();
34
37
  commands.forEach(cmd => multi[cmd.command](...cmd.args));
35
38
  const results = await multi.exec();
36
- return results.map(item => item); // Extract the results from multi.exec response format
39
+ return results.map(item => item);
37
40
  }
38
41
  else {
39
42
  return Promise.all(commands.map(cmd => my.redisClient[cmd.command](...cmd.args)));
@@ -16,9 +16,9 @@ declare class RedisStoreService extends StoreService<RedisClientType, RedisMulti
16
16
  constructor(redisClient: RedisClientType);
17
17
  /**
18
18
  * When in cluster mode, the getMulti wrapper only
19
- * sends commands to the same node/shard.
20
- * All other commands are sent simultaneously
21
- * using Promise.all and are then collated
19
+ * sends commands to the same node/shard if they share a key.
20
+ * All other commands are sent simultaneouslyusing Promise.all
21
+ * and are then collated
22
22
  */
23
23
  getMulti(): RedisMultiType;
24
24
  exec(...args: any[]): Promise<string | string[] | string[][]>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RedisStoreService = void 0;
4
4
  const index_1 = require("../index");
5
+ const enums_1 = require("../../../modules/enums");
5
6
  class RedisStoreService extends index_1.StoreService {
6
7
  constructor(redisClient) {
7
8
  super(redisClient);
@@ -38,13 +39,13 @@ class RedisStoreService extends index_1.StoreService {
38
39
  }
39
40
  /**
40
41
  * When in cluster mode, the getMulti wrapper only
41
- * sends commands to the same node/shard.
42
- * All other commands are sent simultaneously
43
- * using Promise.all and are then collated
42
+ * sends commands to the same node/shard if they share a key.
43
+ * All other commands are sent simultaneouslyusing Promise.all
44
+ * and are then collated
44
45
  */
45
46
  getMulti() {
46
47
  const my = this;
47
- if (process.env.HMSH_IS_CLUSTER === 'true') {
48
+ if (enums_1.HMSH_IS_CLUSTER) {
48
49
  const commands = [];
49
50
  const addCommand = (command, args) => {
50
51
  commands.push({ command: command.toUpperCase(), args });
@@ -57,8 +58,10 @@ class RedisStoreService extends index_1.StoreService {
57
58
  async exec() {
58
59
  if (commands.length === 0)
59
60
  return [];
60
- const sameCommand = commands.every(cmd => cmd.command === commands[0].command);
61
- if (sameCommand) {
61
+ const sameKey = commands.every(cmd => {
62
+ return cmd.args[0] === commands[0].args[0];
63
+ });
64
+ if (sameKey) {
62
65
  const multi = my.redisClient.multi();
63
66
  commands.forEach(cmd => {
64
67
  if (cmd.command === 'ZADD') {
@@ -67,7 +70,7 @@ class RedisStoreService extends index_1.StoreService {
67
70
  return multi[cmd.command](...cmd.args);
68
71
  });
69
72
  const results = await multi.exec();
70
- return results.map(item => item); // Extract the results from multi.exec response format
73
+ return results.map(item => item);
71
74
  }
72
75
  else {
73
76
  return Promise.all(commands.map(cmd => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",