@yieldstar/core 0.1.0 → 0.1.4

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/dist/index.js CHANGED
@@ -96,14 +96,18 @@ class WorkflowRunner {
96
96
  this.schedulerClient = params.schedulerClient;
97
97
  this.router = params.router;
98
98
  }
99
- run = async (task) => {
99
+ run = async (task, logger) => {
100
100
  const { workflowId, executionId } = task;
101
101
  const workflow = this.router[workflowId];
102
102
  if (!workflow) {
103
103
  throw new Error(`No workflow registered for "${workflowId}"`);
104
104
  }
105
105
  try {
106
- const response = await this.runWorkflows({ executionId, workflow });
106
+ const response = await this.runWorkflows({
107
+ executionId,
108
+ workflow,
109
+ logger
110
+ });
107
111
  switch (response.type) {
108
112
  case "workflow-result":
109
113
  return response;
@@ -120,10 +124,11 @@ class WorkflowRunner {
120
124
  }
121
125
  };
122
126
  async runWorkflows(params) {
123
- const { executionId, workflow } = params;
127
+ const { executionId, workflow, logger } = params;
124
128
  const workflowIterator = workflow({
125
129
  heapClient: this.heapClient,
126
- executionId
130
+ executionId,
131
+ logger
127
132
  });
128
133
  const iteratorResult = await workflowIterator.next();
129
134
  const stageResponse = iteratorResult.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yieldstar/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
@@ -1,7 +1,9 @@
1
+ import type { Logger } from "pino";
1
2
  import type { WorkflowResult } from "./step";
2
3
 
3
4
  export type Task = { workflowId: string; executionId: string; params?: any };
4
5
 
5
6
  export type TaskProcessor = <T = any>(
6
- task: Task
7
+ task: Task,
8
+ logger: Logger
7
9
  ) => Promise<void | WorkflowResult<T>>;
@@ -1,9 +1,11 @@
1
+ import type { Logger } from "pino";
1
2
  import { HeapClient } from "./heap";
2
3
  import { StepResponse, WorkflowResult } from "./step";
3
4
 
4
5
  export type WorkflowGenerator<T = any> = (params: {
5
6
  executionId: string;
6
7
  heapClient: HeapClient;
8
+ logger: Logger;
7
9
  }) => AsyncGenerator<StepResponse, WorkflowResult<T>, StepResponse>;
8
10
 
9
11
  export type WorkflowGeneratorReturnType<CG> = CG extends WorkflowGenerator<
@@ -1,3 +1,4 @@
1
+ import type { Logger } from "pino";
1
2
  import type {
2
3
  WorkflowGenerator,
3
4
  HeapClient,
@@ -17,13 +18,14 @@ export class WorkflowRunner<
17
18
  heapClient: HeapClient;
18
19
  schedulerClient: SchedulerClient;
19
20
  router: Router;
21
+ logger: Logger;
20
22
  }) {
21
23
  this.heapClient = params.heapClient;
22
24
  this.schedulerClient = params.schedulerClient;
23
25
  this.router = params.router;
24
26
  }
25
27
 
26
- run: TaskProcessor = async (task) => {
28
+ run: TaskProcessor = async (task, logger) => {
27
29
  const { workflowId, executionId } = task;
28
30
  const workflow = this.router[workflowId];
29
31
 
@@ -32,7 +34,11 @@ export class WorkflowRunner<
32
34
  }
33
35
 
34
36
  try {
35
- const response = await this.runWorkflows({ executionId, workflow });
37
+ const response = await this.runWorkflows({
38
+ executionId,
39
+ workflow,
40
+ logger,
41
+ });
36
42
 
37
43
  switch (response.type) {
38
44
  case "workflow-result":
@@ -55,12 +61,14 @@ export class WorkflowRunner<
55
61
  private async runWorkflows<T>(params: {
56
62
  executionId: string;
57
63
  workflow: WorkflowGenerator<T>;
64
+ logger: Logger;
58
65
  }): Promise<WorkflowResult<T> | WorkflowDelay> {
59
- const { executionId, workflow } = params;
66
+ const { executionId, workflow, logger } = params;
60
67
 
61
68
  const workflowIterator = workflow({
62
69
  heapClient: this.heapClient,
63
70
  executionId,
71
+ logger,
64
72
  });
65
73
 
66
74
  const iteratorResult = await workflowIterator.next();