@hotmeshio/hotmesh 0.0.13 → 0.0.15

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.13",
3
+ "version": "0.0.15",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -136,10 +136,10 @@ class Activity {
136
136
  try {
137
137
  this.setLeg(2);
138
138
  await this.getState(jobId);
139
- const aState = await collator_1.CollatorService.notarizeReentry(this);
140
- this.adjacentIndex = collator_1.CollatorService.getDimensionalIndex(aState);
141
139
  telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
142
140
  telemetry.startActivitySpan(this.leg);
141
+ const aState = await collator_1.CollatorService.notarizeReentry(this);
142
+ this.adjacentIndex = collator_1.CollatorService.getDimensionalIndex(aState);
143
143
  this.bindActivityData('hook');
144
144
  this.mapJobData();
145
145
  this.adjacencyList = await this.filterAdjacent();
@@ -159,6 +159,11 @@ class Activity {
159
159
  return jobStatus;
160
160
  }
161
161
  catch (error) {
162
+ if (error instanceof errors_1.CollationError) {
163
+ //caused by external over-signaling; the job is complete
164
+ this.logger.info('process-hook-event-inactive-error', { error });
165
+ return;
166
+ }
162
167
  this.logger.error('engine-process-hook-event-error', { error });
163
168
  telemetry.setActivityError(error.message);
164
169
  throw error;
@@ -1,6 +1,6 @@
1
1
  import { WorkflowHandleService } from './handle';
2
2
  import { HotMeshService as HotMesh } from '../hotmesh';
3
- import { ClientConfig, Connection, SignalOptions, WorkflowOptions } from '../../types/durable';
3
+ import { ClientConfig, Connection, WorkflowOptions } from '../../types/durable';
4
4
  export declare class ClientService {
5
5
  connection: Connection;
6
6
  options: WorkflowOptions;
@@ -9,7 +9,7 @@ export declare class ClientService {
9
9
  getHotMeshClient: (worflowTopic: string) => Promise<HotMesh>;
10
10
  workflow: {
11
11
  start: (options: WorkflowOptions) => Promise<WorkflowHandleService>;
12
- signal: (options: SignalOptions) => Promise<void>;
12
+ signal: (signalId: string, data: Record<any, any>) => Promise<string>;
13
13
  };
14
14
  activateWorkflow(hotMesh: HotMesh, appId?: string, version?: string): Promise<void>;
15
15
  static shutdown(): Promise<void>;
@@ -95,17 +95,8 @@ class ClientService {
95
95
  const jobId = await hotMeshClient.pub(factory_1.SUBSCRIBES_TOPIC, payload, context);
96
96
  return new handle_1.WorkflowHandleService(hotMeshClient, workflowTopic, jobId);
97
97
  },
98
- //signal in to activate a paused (waitForSignal) workflow
99
- signal: async (options) => {
100
- const taskQueueName = options.taskQueue;
101
- const workflowName = options.workflowName;
102
- const workflowTopic = `${taskQueueName}-${workflowName}`;
103
- const hotMeshClient = await this.getHotMeshClient(workflowTopic);
104
- const payload = {
105
- id: options.workflowId,
106
- data: { ...options.data },
107
- };
108
- await hotMeshClient.hook(factory_1.HOOK_ID, payload);
98
+ signal: async (signalId, data) => {
99
+ return await (await this.getHotMeshClient('durable.wfs.signal')).hook('durable.wfs.signal', { id: signalId, data });
109
100
  }
110
101
  };
111
102
  this.connection = config.connection;
@@ -58,7 +58,7 @@ declare class EngineService {
58
58
  hasParentJob(context: JobState): boolean;
59
59
  resolveError(metadata: JobMetadata): StreamError | undefined;
60
60
  scrub(jobId: string): Promise<void>;
61
- hook(topic: string, data: JobData, dad?: string): Promise<JobStatus | void>;
61
+ hook(topic: string, data: JobData, dad?: string): Promise<string>;
62
62
  hookTime(jobId: string, activityId: string): Promise<JobStatus | void>;
63
63
  hookAll(hookTopic: string, data: JobData, keyResolver: JobStatsInput, queryFacets?: string[]): Promise<string[]>;
64
64
  pub(topic: string, data: JobData, context?: JobState): Promise<string>;
@@ -341,7 +341,7 @@ class EngineService {
341
341
  },
342
342
  data,
343
343
  };
344
- await this.streamSignaler.publishMessage(null, streamData);
344
+ return await this.streamSignaler.publishMessage(null, streamData);
345
345
  }
346
346
  async hookTime(jobId, activityId) {
347
347
  //the activityid is concatenated with its dimensional address (dad); split to resolve
@@ -38,7 +38,7 @@ declare class HotMeshService {
38
38
  getIds(topic: string, query: JobStatsInput, queryFacets?: any[]): Promise<IdsResponse>;
39
39
  resolveQuery(topic: string, query: JobStatsInput): Promise<GetStatsOptions>;
40
40
  scrub(jobId: string): Promise<void>;
41
- hook(topic: string, data: JobData, dad?: string): Promise<JobStatus | void>;
41
+ hook(topic: string, data: JobData, dad?: string): Promise<string>;
42
42
  hookAll(hookTopic: string, data: JobData, query: JobStatsInput, queryFacets?: string[]): Promise<string[]>;
43
43
  stop(): Promise<void>;
44
44
  compress(terms: string[]): Promise<boolean>;
@@ -72,4 +72,4 @@ type ActivityConfig = {
72
72
  maximumInterval: string;
73
73
  };
74
74
  };
75
- export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, NativeConnection, ProxyType, Registry, SignalOptions, WorkerConfig, WorkerOptions, WorkflowDataType, WorkflowOptions, };
75
+ export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, NativeConnection, ProxyType, Registry, SignalOptions, WorkerConfig, WorkflowConfig, WorkerOptions, WorkflowDataType, WorkflowOptions, };
@@ -3,7 +3,7 @@ export { App, AppVID, AppTransitions, AppSubscriptions } from './app';
3
3
  export { AsyncSignal } from './async';
4
4
  export { CacheMode } from './cache';
5
5
  export { CollationFaultType, CollationStage } from './collator';
6
- export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, NativeConnection, ProxyType, Registry, WorkerConfig, WorkerOptions, WorkflowDataType, WorkflowOptions, } from './durable';
6
+ export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, NativeConnection, ProxyType, Registry, WorkflowConfig, WorkerConfig, WorkerOptions, WorkflowDataType, WorkflowOptions, } from './durable';
7
7
  export { HookCondition, HookConditions, HookGate, HookInterface, HookRule, HookRules, HookSignal } from './hook';
8
8
  export { RedisClientType as IORedisClientType, RedisMultiType as IORedisMultiType } from './ioredisclient';
9
9
  export { ILogger } from './logger';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { GetStateError } from '../../modules/errors';
1
+ import { CollationError, GetStateError } from '../../modules/errors';
2
2
  import {
3
3
  formatISODate,
4
4
  getValueByPath,
@@ -183,11 +183,11 @@ class Activity {
183
183
  try {
184
184
  this.setLeg(2);
185
185
  await this.getState(jobId);
186
+ telemetry = new TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
187
+ telemetry.startActivitySpan(this.leg);
186
188
  const aState = await CollatorService.notarizeReentry(this);
187
189
  this.adjacentIndex = CollatorService.getDimensionalIndex(aState);
188
190
 
189
- telemetry = new TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
190
- telemetry.startActivitySpan(this.leg);
191
191
  this.bindActivityData('hook');
192
192
  this.mapJobData();
193
193
  this.adjacencyList = await this.filterAdjacent();
@@ -209,6 +209,11 @@ class Activity {
209
209
  telemetry.setActivityAttributes(attrs);
210
210
  return jobStatus as number;
211
211
  } catch (error) {
212
+ if (error instanceof CollationError) {
213
+ //caused by external over-signaling; the job is complete
214
+ this.logger.info('process-hook-event-inactive-error', { error });
215
+ return;
216
+ }
212
217
  this.logger.error('engine-process-hook-event-error', { error });
213
218
  telemetry.setActivityError(error.message);
214
219
  throw error;
@@ -1,11 +1,10 @@
1
1
  import { nanoid } from 'nanoid';
2
- import { APP_ID, APP_VERSION, DEFAULT_COEFFICIENT, HOOK_ID, SUBSCRIBES_TOPIC, getWorkflowYAML } from './factory';
2
+ import { APP_ID, APP_VERSION, DEFAULT_COEFFICIENT, SUBSCRIBES_TOPIC, getWorkflowYAML } from './factory';
3
3
  import { WorkflowHandleService } from './handle';
4
4
  import { HotMeshService as HotMesh } from '../hotmesh';
5
5
  import {
6
6
  ClientConfig,
7
7
  Connection,
8
- SignalOptions,
9
8
  WorkflowOptions } from '../../types/durable';
10
9
  import { JobState } from '../../types/job';
11
10
  import { KeyType } from '../../modules/key';
@@ -114,22 +113,10 @@ export class ClientService {
114
113
  return new WorkflowHandleService(hotMeshClient, workflowTopic, jobId);
115
114
  },
116
115
 
117
- //signal in to activate a paused (waitForSignal) workflow
118
- signal: async (options: SignalOptions): Promise<void> => {
119
- const taskQueueName = options.taskQueue;
120
- const workflowName = options.workflowName;
121
- const workflowTopic = `${taskQueueName}-${workflowName}`;
122
- const hotMeshClient = await this.getHotMeshClient(workflowTopic);
123
- const payload = {
124
- id: options.workflowId,
125
- data: { ...options.data },
126
- }
127
- await hotMeshClient.hook(
128
- HOOK_ID,
129
- payload
130
- );
116
+ signal: async (signalId: string, data: Record<any, any>): Promise<string> => {
117
+ return await (await this.getHotMeshClient('durable.wfs.signal')).hook('durable.wfs.signal', { id: signalId, data });
131
118
  }
132
- };
119
+ }
133
120
 
134
121
  async activateWorkflow(hotMesh: HotMesh, appId = APP_ID, version = APP_VERSION): Promise<void> {
135
122
  const app = await hotMesh.engine.store.getApp(appId);
@@ -413,7 +413,7 @@ class EngineService {
413
413
  }
414
414
 
415
415
  // ****************** `HOOK` ACTIVITY RE-ENTRY POINT *****************
416
- async hook(topic: string, data: JobData, dad?: string): Promise<JobStatus | void> {
416
+ async hook(topic: string, data: JobData, dad?: string): Promise<string> {
417
417
  const hookRule = await this.storeSignaler.getHookRule(topic);
418
418
  const [aid, schema] = await this.getSchema(`.${hookRule.to}`);
419
419
  if (!dad) {
@@ -432,7 +432,7 @@ class EngineService {
432
432
  },
433
433
  data,
434
434
  };
435
- await this.streamSignaler.publishMessage(null, streamData);
435
+ return await this.streamSignaler.publishMessage(null, streamData) as string;
436
436
  }
437
437
  async hookTime(jobId: string, activityId: string): Promise<JobStatus | void> {
438
438
  //the activityid is concatenated with its dimensional address (dad); split to resolve
@@ -165,7 +165,7 @@ class HotMeshService {
165
165
  }
166
166
 
167
167
  // ****** `HOOK` ACTIVITY RE-ENTRY POINT ******
168
- async hook(topic: string, data: JobData, dad?: string): Promise<JobStatus | void> {
168
+ async hook(topic: string, data: JobData, dad?: string): Promise<string> {
169
169
  return await this.engine?.hook(topic, data, dad);
170
170
  }
171
171
  async hookAll(hookTopic: string, data: JobData, query: JobStatsInput, queryFacets: string[] = []): Promise<string[]> {
package/types/durable.ts CHANGED
@@ -98,6 +98,7 @@ export {
98
98
  Registry,
99
99
  SignalOptions,
100
100
  WorkerConfig,
101
+ WorkflowConfig,
101
102
  WorkerOptions,
102
103
  WorkflowDataType,
103
104
  WorkflowOptions,
package/types/index.ts CHANGED
@@ -36,6 +36,7 @@ export {
36
36
  NativeConnection,
37
37
  ProxyType,
38
38
  Registry,
39
+ WorkflowConfig,
39
40
  WorkerConfig,
40
41
  WorkerOptions,
41
42
  WorkflowDataType,