@hotmeshio/hotmesh 0.0.30 → 0.0.31

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.30",
3
+ "version": "0.0.31",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -31,16 +31,16 @@ class WorkflowService {
31
31
  const workflowSpan = store.get('workflowSpan');
32
32
  const COUNTER = store.get('counter');
33
33
  const execIndex = COUNTER.counter = COUNTER.counter + 1;
34
- const prefix = options.prefix ?? '';
35
- //this is risky but MUST be allowed. Users MAY set the workflowId,
36
- //but if there is a naming collision, the data from the target entity will be used
37
- //as there is know way of knowing if the item was generated via a prior run of the workflow
38
- const childJobId = options.workflowId ?? `${prefix}-${workflowId}-$${options.workflowName}${workflowDimension}-${execIndex}`;
34
+ //NOTE: this is the hash prefix; necessary for the search index to locate the entity
35
+ //if the hash is a helper, a dash begins it, so it isn't indexed
36
+ const entityOrEmptyString = options.entity ?? '';
37
+ //If the workflowId is not provided, it is generated from the entity and the workflow name
38
+ const childJobId = options.workflowId ?? `${entityOrEmptyString}-${workflowId}-$${options.entity ?? options.workflowName}${workflowDimension}-${execIndex}`;
39
39
  const parentWorkflowId = `${workflowId}-f`;
40
40
  const client = new client_1.ClientService({
41
41
  connection: await connection_1.ConnectionService.connect(worker_1.WorkerService.connection),
42
42
  });
43
- let handle = await client.workflow.getHandle(options.taskQueue, options.workflowName, childJobId, namespace);
43
+ let handle = await client.workflow.getHandle(options.entity ?? options.taskQueue, options.entity ?? options.workflowName, childJobId, namespace);
44
44
  try {
45
45
  return await handle.result(true);
46
46
  }
@@ -73,10 +73,12 @@ class WorkflowService {
73
73
  const workflowSpan = store.get('workflowSpan');
74
74
  const COUNTER = store.get('counter');
75
75
  const execIndex = COUNTER.counter = COUNTER.counter + 1;
76
- const prefix = options.prefix ?? '';
77
- const childJobId = options.workflowId ?? `${prefix}-${workflowId}-$${options.workflowName}${workflowDimension}-${execIndex}`;
76
+ //NOTE: this is the hash prefix; necessary for the search index to locate the entity
77
+ const entityOrEmptyString = options.entity ?? '';
78
+ //If the workflowId is not provided, it is generated from the entity and the workflow name
79
+ const childJobId = options.workflowId ?? `${entityOrEmptyString}-${workflowId}-$${options.entity ?? options.workflowName}${workflowDimension}-${execIndex}`;
78
80
  const parentWorkflowId = `${workflowId}-f`;
79
- const workflowTopic = `${options.taskQueue}-${options.workflowName}`;
81
+ const workflowTopic = `${options.entity ?? options.taskQueue}-${options.entity ?? options.workflowName}`;
80
82
  try {
81
83
  //get the status; if there is no error, return childJobId (what was spawned)
82
84
  const hotMeshClient = await worker_1.WorkerService.getHotMesh(workflowTopic, { namespace });
@@ -247,8 +249,8 @@ class WorkflowService {
247
249
  const store = asyncLocalStorage_1.asyncLocalStorage.getStore();
248
250
  const workflowId = options.workflowId ?? store.get('workflowId');
249
251
  let workflowTopic = store.get('workflowTopic');
250
- if (options.taskQueue && options.workflowName) {
251
- workflowTopic = `${options.taskQueue}-${options.workflowName}`;
252
+ if (options.entity || (options.taskQueue && options.workflowName)) {
253
+ workflowTopic = `${options.entity ?? options.taskQueue}-${options.entity ?? options.workflowName}`;
252
254
  } //else this is essentially recursion as the function calls itself
253
255
  const payload = {
254
256
  arguments: [...options.args],
@@ -220,7 +220,6 @@ 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);
224
223
  }
225
224
  async stopConsuming() {
226
225
  this.shouldConsume = false;
@@ -49,7 +49,7 @@ type WorkflowOptions = {
49
49
  taskQueue: string;
50
50
  args: any[];
51
51
  workflowId?: string;
52
- prefix?: string;
52
+ entity?: string;
53
53
  workflowName?: string;
54
54
  parentWorkflowId?: string;
55
55
  workflowTrace?: string;
@@ -61,6 +61,7 @@ type HookOptions = {
61
61
  namespace?: string;
62
62
  taskQueue?: string;
63
63
  args: any[];
64
+ entity?: string;
64
65
  workflowId?: string;
65
66
  workflowName?: string;
66
67
  search?: WorkflowSearchOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -39,11 +39,11 @@ export class WorkflowService {
39
39
  const workflowSpan = store.get('workflowSpan');
40
40
  const COUNTER = store.get('counter');
41
41
  const execIndex = COUNTER.counter = COUNTER.counter + 1;
42
- const prefix = options.prefix ?? '';
43
- //this is risky but MUST be allowed. Users MAY set the workflowId,
44
- //but if there is a naming collision, the data from the target entity will be used
45
- //as there is know way of knowing if the item was generated via a prior run of the workflow
46
- const childJobId = options.workflowId ?? `${prefix}-${workflowId}-$${options.workflowName}${workflowDimension}-${execIndex}`;
42
+ //NOTE: this is the hash prefix; necessary for the search index to locate the entity
43
+ //if the hash is a helper, a dash begins it, so it isn't indexed
44
+ const entityOrEmptyString = options.entity ?? '';
45
+ //If the workflowId is not provided, it is generated from the entity and the workflow name
46
+ const childJobId = options.workflowId ?? `${entityOrEmptyString}-${workflowId}-$${options.entity ?? options.workflowName}${workflowDimension}-${execIndex}`;
47
47
  const parentWorkflowId = `${workflowId}-f`;
48
48
 
49
49
  const client = new Client({
@@ -51,8 +51,8 @@ export class WorkflowService {
51
51
  });
52
52
 
53
53
  let handle = await client.workflow.getHandle(
54
- options.taskQueue,
55
- options.workflowName,
54
+ options.entity ?? options.taskQueue,
55
+ options.entity ?? options.workflowName,
56
56
  childJobId,
57
57
  namespace,
58
58
  );
@@ -89,10 +89,12 @@ export class WorkflowService {
89
89
  const workflowSpan = store.get('workflowSpan');
90
90
  const COUNTER = store.get('counter');
91
91
  const execIndex = COUNTER.counter = COUNTER.counter + 1;
92
- const prefix = options.prefix ?? '';
93
- const childJobId = options.workflowId ?? `${prefix}-${workflowId}-$${options.workflowName}${workflowDimension}-${execIndex}`;
92
+ //NOTE: this is the hash prefix; necessary for the search index to locate the entity
93
+ const entityOrEmptyString = options.entity ?? '';
94
+ //If the workflowId is not provided, it is generated from the entity and the workflow name
95
+ const childJobId = options.workflowId ?? `${entityOrEmptyString}-${workflowId}-$${options.entity ?? options.workflowName}${workflowDimension}-${execIndex}`;
94
96
  const parentWorkflowId = `${workflowId}-f`;
95
- const workflowTopic = `${options.taskQueue}-${options.workflowName}`;
97
+ const workflowTopic = `${options.entity ?? options.taskQueue}-${options.entity ?? options.workflowName}`;
96
98
 
97
99
  try {
98
100
  //get the status; if there is no error, return childJobId (what was spawned)
@@ -273,8 +275,8 @@ export class WorkflowService {
273
275
  const store = asyncLocalStorage.getStore();
274
276
  const workflowId = options.workflowId ?? store.get('workflowId');
275
277
  let workflowTopic = store.get('workflowTopic');
276
- if (options.taskQueue && options.workflowName) {
277
- workflowTopic = `${options.taskQueue}-${options.workflowName}`;
278
+ if (options.entity || (options.taskQueue && options.workflowName)) {
279
+ workflowTopic = `${options.entity ?? options.taskQueue}-${options.entity ?? options.workflowName}`;
278
280
  } //else this is essentially recursion as the function calls itself
279
281
  const payload = {
280
282
  arguments: [...options.args],
@@ -254,7 +254,6 @@ class StreamSignaler {
254
254
  for (const instance of [...StreamSignaler.signalers]) {
255
255
  instance.stopConsuming();
256
256
  }
257
- await sleepFor(BLOCK_TIME_MS);
258
257
  }
259
258
 
260
259
  async stopConsuming() {
package/types/durable.ts CHANGED
@@ -57,7 +57,7 @@ type WorkflowOptions = {
57
57
  taskQueue: string;
58
58
  args: any[]; //input arguments to pass in
59
59
  workflowId?: string; //execution id (the job id)
60
- prefix?: string; //If invoking a hook, the prefix ensures the FT.SEARCH index is properly scoped to those documents with this prefix
60
+ entity?: string; //If invoking a workflow, passing 'entity' will apply the value as the workflowName, taskQueue, and prefix, ensuring the FT.SEARCH index is properly scoped. This is a convenience method but limits options.
61
61
  workflowName?: string; //the name of the user's workflow function
62
62
  parentWorkflowId?: string; //system reserved; the id of the parent; if present the flow will not self-clean until the parent that spawned it self-cleans
63
63
  workflowTrace?: string;
@@ -70,6 +70,7 @@ type HookOptions = {
70
70
  namespace?: string; //'durable' is the default namespace if not provided; similar to setting `appid` in the YAML
71
71
  taskQueue?: string;
72
72
  args: any[]; //input arguments to pass into the hook
73
+ entity?: string; //If invoking a hook, passing 'entity' will apply the value as the workflowName, taskQueue, and prefix, ensuring the FT.SEARCH index is properly scoped. This is a convenience method but limits options.
73
74
  workflowId?: string; //execution id (the job id to hook into)
74
75
  workflowName?: string; //the name of the user's hook function
75
76
  search?: WorkflowSearchOptions //bind additional search terms immediately before hook reentry