@hotmeshio/hotmesh 0.0.5 → 0.0.6

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.5",
3
+ "version": "0.0.6",
4
4
  "description": "Durable Workflows",
5
5
  "main": "build/cjs/index.js",
6
6
  "module": "build/esm/index.js",
@@ -320,8 +320,8 @@ class Activity {
320
320
  telemetry_1.TelemetryService.addTargetTelemetryPaths(consumes, this.config, this.metadata, this.leg);
321
321
  let { dad, jid } = this.context.metadata;
322
322
  jobId = jobId || jid;
323
- //`state` is a flat hash
324
323
  const dIds = collator_1.CollatorService.getDimensionsById([...this.config.ancestors, this.metadata.aid], dad);
324
+ //`state` is a flat hash
325
325
  const [state, status] = await this.store.getState(jobId, consumes, dIds);
326
326
  //`context` is a tree
327
327
  this.context = (0, utils_1.restoreHierarchy)(state);
@@ -20,6 +20,7 @@ export declare class WorkerService {
20
20
  */
21
21
  static registerActivities<ACT>(activities: ACT): Registry;
22
22
  static create(config: WorkerConfig): Promise<WorkerService>;
23
+ static resolveWorkflowTarget(workflow: object | Function): [string, Function];
23
24
  run(): Promise<void>;
24
25
  initActivityWorkflow(config: WorkerConfig, activityTopic: string): Promise<HotMesh>;
25
26
  wrapActivityFunctions(): Function;
@@ -110,9 +110,7 @@ class WorkerService {
110
110
  WorkerService.registerActivities(config.activities);
111
111
  //import the user's workflow file (triggers activity functions to be wrapped)
112
112
  const workflow = await Promise.resolve(`${config.workflowsPath}`).then(s => __importStar(require(s)));
113
- const workflowFunctionNames = Object.keys(workflow);
114
- const workflowFunctionName = workflowFunctionNames[workflowFunctionNames.length - 1];
115
- const workflowFunction = workflow[workflowFunctionName];
113
+ const [workflowFunctionName, workflowFunction] = WorkerService.resolveWorkflowTarget(workflow);
116
114
  const baseTopic = `${config.taskQueue}-${workflowFunctionName}`;
117
115
  const activityTopic = `${baseTopic}-activity`;
118
116
  const workflowTopic = `${baseTopic}`;
@@ -124,6 +122,18 @@ class WorkerService {
124
122
  await WorkerService.activateWorkflow(worker.workflowRunner, workflowTopic, factory_1.getWorkflowYAML);
125
123
  return worker;
126
124
  }
125
+ static resolveWorkflowTarget(workflow) {
126
+ let workflowFunction;
127
+ if (typeof workflow === 'function') {
128
+ workflowFunction = workflow;
129
+ }
130
+ else {
131
+ const workflowFunctionNames = Object.keys(workflow);
132
+ workflowFunction = workflow[workflowFunctionNames[workflowFunctionNames.length - 1]];
133
+ return WorkerService.resolveWorkflowTarget(workflowFunction);
134
+ }
135
+ return [workflowFunction.name, workflowFunction];
136
+ }
127
137
  async run() {
128
138
  if (this.workflowRunner) {
129
139
  this.workflowRunner.engine.logger.info('WorkerService is running');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Durable Workflows",
5
5
  "main": "build/cjs/index.js",
6
6
  "module": "build/esm/index.js",
@@ -317,8 +317,8 @@ class Activity {
317
317
  TelemetryService.addTargetTelemetryPaths(consumes, this.config, this.metadata, this.leg);
318
318
  let { dad, jid } = this.context.metadata;
319
319
  jobId = jobId || jid;
320
- //`state` is a flat hash
321
320
  const dIds = CollatorService.getDimensionsById([...this.config.ancestors, this.metadata.aid], dad);
321
+ //`state` is a flat hash
322
322
  const [state, status] = await this.store.getState(jobId, consumes, dIds);
323
323
  //`context` is a tree
324
324
  this.context = restoreHierarchy(state);
@@ -20,6 +20,7 @@ export declare class WorkerService {
20
20
  */
21
21
  static registerActivities<ACT>(activities: ACT): Registry;
22
22
  static create(config: WorkerConfig): Promise<WorkerService>;
23
+ static resolveWorkflowTarget(workflow: object | Function): [string, Function];
23
24
  run(): Promise<void>;
24
25
  initActivityWorkflow(config: WorkerConfig, activityTopic: string): Promise<HotMesh>;
25
26
  wrapActivityFunctions(): Function;
@@ -84,9 +84,7 @@ class WorkerService {
84
84
  WorkerService.registerActivities(config.activities);
85
85
  //import the user's workflow file (triggers activity functions to be wrapped)
86
86
  const workflow = await import(config.workflowsPath);
87
- const workflowFunctionNames = Object.keys(workflow);
88
- const workflowFunctionName = workflowFunctionNames[workflowFunctionNames.length - 1];
89
- const workflowFunction = workflow[workflowFunctionName];
87
+ const [workflowFunctionName, workflowFunction] = WorkerService.resolveWorkflowTarget(workflow);
90
88
  const baseTopic = `${config.taskQueue}-${workflowFunctionName}`;
91
89
  const activityTopic = `${baseTopic}-activity`;
92
90
  const workflowTopic = `${baseTopic}`;
@@ -98,6 +96,18 @@ class WorkerService {
98
96
  await WorkerService.activateWorkflow(worker.workflowRunner, workflowTopic, getWorkflowYAML);
99
97
  return worker;
100
98
  }
99
+ static resolveWorkflowTarget(workflow) {
100
+ let workflowFunction;
101
+ if (typeof workflow === 'function') {
102
+ workflowFunction = workflow;
103
+ }
104
+ else {
105
+ const workflowFunctionNames = Object.keys(workflow);
106
+ workflowFunction = workflow[workflowFunctionNames[workflowFunctionNames.length - 1]];
107
+ return WorkerService.resolveWorkflowTarget(workflowFunction);
108
+ }
109
+ return [workflowFunction.name, workflowFunction];
110
+ }
101
111
  async run() {
102
112
  if (this.workflowRunner) {
103
113
  this.workflowRunner.engine.logger.info('WorkerService is running');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Durable Workflows",
5
5
  "main": "build/cjs/index.js",
6
6
  "module": "build/esm/index.js",
@@ -391,8 +391,8 @@ class Activity {
391
391
  TelemetryService.addTargetTelemetryPaths(consumes, this.config, this.metadata, this.leg);
392
392
  let { dad, jid } = this.context.metadata;
393
393
  jobId = jobId || jid;
394
- //`state` is a flat hash
395
394
  const dIds = CollatorService.getDimensionsById([...this.config.ancestors, this.metadata.aid], dad);
395
+ //`state` is a flat hash
396
396
  const [state, status] = await this.store.getState(jobId, consumes, dIds);
397
397
  //`context` is a tree
398
398
  this.context = restoreHierarchy(state) as JobState;
@@ -104,9 +104,7 @@ export class WorkerService {
104
104
  WorkerService.registerActivities<typeof config.activities>(config.activities);
105
105
  //import the user's workflow file (triggers activity functions to be wrapped)
106
106
  const workflow = await import(config.workflowsPath);
107
- const workflowFunctionNames = Object.keys(workflow);
108
- const workflowFunctionName = workflowFunctionNames[workflowFunctionNames.length - 1];
109
- const workflowFunction = workflow[workflowFunctionName];
107
+ const [workflowFunctionName, workflowFunction] = WorkerService.resolveWorkflowTarget(workflow);
110
108
  const baseTopic = `${config.taskQueue}-${workflowFunctionName}`;
111
109
  const activityTopic = `${baseTopic}-activity`;
112
110
  const workflowTopic = `${baseTopic}`;
@@ -121,6 +119,18 @@ export class WorkerService {
121
119
  return worker;
122
120
  }
123
121
 
122
+ static resolveWorkflowTarget(workflow: object | Function): [string, Function] {
123
+ let workflowFunction: Function;
124
+ if (typeof workflow === 'function') {
125
+ workflowFunction = workflow;
126
+ } else {
127
+ const workflowFunctionNames = Object.keys(workflow);
128
+ workflowFunction = workflow[workflowFunctionNames[workflowFunctionNames.length - 1]];
129
+ return WorkerService.resolveWorkflowTarget(workflowFunction);
130
+ }
131
+ return [workflowFunction.name, workflowFunction];
132
+ }
133
+
124
134
  async run() {
125
135
  if (this.workflowRunner) {
126
136
  this.workflowRunner.engine.logger.info('WorkerService is running');