@hotmeshio/hotmesh 0.1.5 → 0.1.7

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.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "test:durable:signal": "NODE_ENV=test jest ./tests/durable/signal/index.test.ts --detectOpenHandles --forceExit --verbose",
42
42
  "test:durable:unknown": "NODE_ENV=test jest ./tests/durable/unknown/index.test.ts --detectOpenHandles --forceExit --verbose",
43
43
  "test:emit": "NODE_ENV=test jest ./tests/functional/emit/index.test.ts --detectOpenHandles --forceExit --verbose",
44
- "test:expired": "NODE_ENV=test jest ./tests/functional/expired/index.test.ts --detectOpenHandles --forceExit --verbose",
44
+ "test:pending": "NODE_ENV=test jest ./tests/functional/pending/index.test.ts --detectOpenHandles --forceExit --verbose",
45
45
  "test:functional": "NODE_ENV=test jest ./tests/functional/*/index.test.ts --detectOpenHandles --forceExit --verbose",
46
46
  "test:hmsh": "NODE_ENV=test jest ./tests/functional/index.test.ts --detectOpenHandles --verbose",
47
47
  "test:hook": "NODE_ENV=test jest ./tests/functional/hook/index.test.ts --detectOpenHandles --forceExit --verbose",
@@ -25,16 +25,16 @@ class Trigger extends activity_1.Activity {
25
25
  telemetry.startJobSpan();
26
26
  telemetry.startActivitySpan(this.leg);
27
27
  this.mapJobData();
28
- await this.setStateNX(options?.expired ? -1 : undefined);
28
+ await this.setStateNX(options?.pending ? -1 : undefined);
29
29
  this.adjacencyList = await this.filterAdjacent();
30
- await this.setStatus(options?.expired ? -1 : this.adjacencyList.length);
30
+ await this.setStatus(options?.pending ? -1 : this.adjacencyList.length);
31
31
  this.bindSearchData(options);
32
32
  this.bindMarkerData(options);
33
33
  const multi = this.store.getMulti();
34
34
  await this.setState(multi);
35
35
  await this.setStats(multi);
36
- if (options?.expired) {
37
- await this.setExpired(options?.expired, multi);
36
+ if (options?.pending) {
37
+ await this.setExpired(options?.pending, multi);
38
38
  }
39
39
  else {
40
40
  await this.registerJobDependency(multi);
@@ -47,8 +47,7 @@ class Trigger extends activity_1.Activity {
47
47
  const jobStatus = Number(this.context.metadata.js);
48
48
  telemetry.setJobAttributes({ 'app.job.jss': jobStatus });
49
49
  const attrs = { 'app.job.jss': jobStatus };
50
- //only transition if not inited in an expired state
51
- //todo: enable resume from expired state
50
+ //todo: enable resume from pending state
52
51
  if (jobStatus !== -1) {
53
52
  const messageIds = await this.transition(this.adjacencyList, jobStatus);
54
53
  if (messageIds.length) {
@@ -76,7 +76,7 @@ class ClientService {
76
76
  const jobId = await hotMeshClient.pub(`${options.namespace ?? factory_1.APP_ID}.execute`, payload, context, {
77
77
  search: options?.search?.data,
78
78
  marker: options?.marker,
79
- expired: options?.expired,
79
+ pending: options?.pending,
80
80
  });
81
81
  return new handle_1.WorkflowHandleService(hotMeshClient, workflowTopic, jobId);
82
82
  },
@@ -40,23 +40,23 @@ class ExporterService {
40
40
  //transitions
41
41
  this.inflateTransition(match, value, transitionsObject);
42
42
  }
43
- else if (key.length === 3) {
44
- //state
45
- state[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
46
- }
47
43
  else if (key.startsWith('_')) {
48
44
  //data
49
45
  data[key.substring(1)] = value;
50
46
  }
51
47
  else if (key.startsWith('-')) {
52
48
  //timeline
53
- const keyParts = this.keyToObject(key); //key parts have meaning
49
+ const keyParts = this.keyToObject(key);
54
50
  timeline.push({
55
51
  ...keyParts,
56
52
  key,
57
53
  value: this.resolveValue(value, options.values),
58
54
  });
59
55
  }
56
+ else if (key.length === 3) {
57
+ //state
58
+ state[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
59
+ }
60
60
  });
61
61
  return this.filterFields({
62
62
  data: (0, utils_1.restoreHierarchy)(data),
@@ -116,9 +116,9 @@ class EngineService {
116
116
  }
117
117
  }
118
118
  setCacheMode(cacheMode, untilVersion) {
119
- this.logger.info(`engine-cache-updated`, {
119
+ this.logger.info(`engine-executable-cache`, {
120
120
  mode: cacheMode,
121
- until: untilVersion,
121
+ [cacheMode === 'cache' ? 'target' : 'until']: untilVersion,
122
122
  });
123
123
  this.cacheMode = cacheMode;
124
124
  this.untilVersion = untilVersion;
@@ -1013,7 +1013,9 @@ class StoreService {
1013
1013
  //if a topic, update one
1014
1014
  const rate = options.throttle.toString();
1015
1015
  if (options.topic) {
1016
- await this.redisClient[this.commands.hset](key, { [options.topic]: rate });
1016
+ await this.redisClient[this.commands.hset](key, {
1017
+ [options.topic]: rate,
1018
+ });
1017
1019
  }
1018
1020
  else {
1019
1021
  //if no topic, update all
@@ -1029,13 +1031,22 @@ class StoreService {
1029
1031
  return response ?? {};
1030
1032
  }
1031
1033
  async getThrottleRate(topic) {
1034
+ //always return a valid number range
1035
+ const resolveRate = (response, topic) => {
1036
+ const rate = topic in response ? Number(response[topic]) : 0;
1037
+ if (isNaN(rate))
1038
+ return 0;
1039
+ if (rate == -1)
1040
+ return enums_1.MAX_DELAY;
1041
+ return Math.max(Math.min(rate, enums_1.MAX_DELAY), 0);
1042
+ };
1032
1043
  const response = await this.getThrottleRates();
1033
- const rate = topic in response ? Number(response[topic]) : 0;
1034
- if (isNaN(rate))
1035
- return 0;
1036
- if (rate == -1)
1037
- return enums_1.MAX_DELAY;
1038
- return Math.max(Math.min(rate, enums_1.MAX_DELAY), 0);
1044
+ const globalRate = resolveRate(response, ':');
1045
+ if (topic === ':' || !(topic in response)) {
1046
+ //use global rate unless worker specifies rate
1047
+ return globalRate;
1048
+ }
1049
+ return resolveRate(response, topic);
1039
1050
  }
1040
1051
  }
1041
1052
  exports.StoreService = StoreService;
@@ -261,16 +261,16 @@ type WorkflowOptions = {
261
261
  */
262
262
  await?: boolean;
263
263
  /**
264
- * If provided, the job will initialize in an expired state, reserving
264
+ * If provided, the job will initialize in a pending state, reserving
265
265
  * only the job ID (HSETNX) and persisting search and marker (if provided).
266
266
  * If a `resume` signal is sent before the specified number of seconds,
267
- * the job will resume as normal, transition to the adjacent children
267
+ * the job will resume as normal, transitioning to the adjacent children
268
268
  * of the trigger. If the job is not resumed within the number
269
269
  * of seconds specified, the job will be scrubbed. No dependencies
270
- * are added for a job in an expired state; however, dependencies
270
+ * are added for a job in a pending state; however, dependencies
271
271
  * will be added after the job is resumed if relevant.
272
272
  */
273
- expired?: number;
273
+ pending?: number;
274
274
  };
275
275
  /**
276
276
  * Options for setting up a hook.
@@ -78,16 +78,16 @@ type ExtensionType = {
78
78
  */
79
79
  marker?: StringStringType;
80
80
  /**
81
- * If provided, the job will initialize in an expired state, reserving
81
+ * If provided, the job will initialize in a pending state, reserving
82
82
  * only the job ID (HSETNX) and persisting search and marker (if provided).
83
83
  * If a `resume` signal is sent before the specified number of seconds,
84
- * the job will resume as normal, transition the the adjacent children
85
- * of the trigger. If the job is not resumed within the
86
- * number of seconds specified, the job will be scrubbed. No dependencies
87
- * are added for a job in an expired state; however, dependencies will be
88
- * added after the job is resumed if relevant.
84
+ * the job will resume as normal, transitioning to the adjacent children
85
+ * of the trigger. If the job is not resumed within the number
86
+ * of seconds specified, the job will be scrubbed. No dependencies
87
+ * are added for a job in a pending state; however, dependencies
88
+ * will be added after the job is resumed if relevant.
89
89
  */
90
- expired?: number;
90
+ pending?: number;
91
91
  };
92
92
  /**
93
93
  * job_status semaphore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "test:durable:signal": "NODE_ENV=test jest ./tests/durable/signal/index.test.ts --detectOpenHandles --forceExit --verbose",
42
42
  "test:durable:unknown": "NODE_ENV=test jest ./tests/durable/unknown/index.test.ts --detectOpenHandles --forceExit --verbose",
43
43
  "test:emit": "NODE_ENV=test jest ./tests/functional/emit/index.test.ts --detectOpenHandles --forceExit --verbose",
44
- "test:expired": "NODE_ENV=test jest ./tests/functional/expired/index.test.ts --detectOpenHandles --forceExit --verbose",
44
+ "test:pending": "NODE_ENV=test jest ./tests/functional/pending/index.test.ts --detectOpenHandles --forceExit --verbose",
45
45
  "test:functional": "NODE_ENV=test jest ./tests/functional/*/index.test.ts --detectOpenHandles --forceExit --verbose",
46
46
  "test:hmsh": "NODE_ENV=test jest ./tests/functional/index.test.ts --detectOpenHandles --verbose",
47
47
  "test:hook": "NODE_ENV=test jest ./tests/functional/hook/index.test.ts --detectOpenHandles --forceExit --verbose",
package/types/durable.ts CHANGED
@@ -315,16 +315,16 @@ type WorkflowOptions = {
315
315
  await?: boolean;
316
316
 
317
317
  /**
318
- * If provided, the job will initialize in an expired state, reserving
318
+ * If provided, the job will initialize in a pending state, reserving
319
319
  * only the job ID (HSETNX) and persisting search and marker (if provided).
320
320
  * If a `resume` signal is sent before the specified number of seconds,
321
- * the job will resume as normal, transition to the adjacent children
321
+ * the job will resume as normal, transitioning to the adjacent children
322
322
  * of the trigger. If the job is not resumed within the number
323
323
  * of seconds specified, the job will be scrubbed. No dependencies
324
- * are added for a job in an expired state; however, dependencies
324
+ * are added for a job in a pending state; however, dependencies
325
325
  * will be added after the job is resumed if relevant.
326
326
  */
327
- expired?: number;
327
+ pending?: number;
328
328
  };
329
329
 
330
330
  /**
package/types/job.ts CHANGED
@@ -108,16 +108,16 @@ type ExtensionType = {
108
108
  marker?: StringStringType;
109
109
 
110
110
  /**
111
- * If provided, the job will initialize in an expired state, reserving
111
+ * If provided, the job will initialize in a pending state, reserving
112
112
  * only the job ID (HSETNX) and persisting search and marker (if provided).
113
113
  * If a `resume` signal is sent before the specified number of seconds,
114
- * the job will resume as normal, transition the the adjacent children
115
- * of the trigger. If the job is not resumed within the
116
- * number of seconds specified, the job will be scrubbed. No dependencies
117
- * are added for a job in an expired state; however, dependencies will be
118
- * added after the job is resumed if relevant.
114
+ * the job will resume as normal, transitioning to the adjacent children
115
+ * of the trigger. If the job is not resumed within the number
116
+ * of seconds specified, the job will be scrubbed. No dependencies
117
+ * are added for a job in a pending state; however, dependencies
118
+ * will be added after the job is resumed if relevant.
119
119
  */
120
- expired?: number;
120
+ pending?: number;
121
121
  };
122
122
 
123
123
  /**