@pgflow/edge-worker 0.1.14 → 0.1.16

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.
Files changed (81) hide show
  1. package/package.json +4 -4
  2. package/dist/CHANGELOG.md +0 -268
  3. package/dist/EdgeWorker.d.ts +0 -121
  4. package/dist/EdgeWorker.d.ts.map +0 -1
  5. package/dist/EdgeWorker.js +0 -168
  6. package/dist/LICENSE.md +0 -660
  7. package/dist/README.md +0 -46
  8. package/dist/core/BatchProcessor.d.ts +0 -13
  9. package/dist/core/BatchProcessor.d.ts.map +0 -1
  10. package/dist/core/BatchProcessor.js +0 -29
  11. package/dist/core/ExecutionController.d.ts +0 -15
  12. package/dist/core/ExecutionController.d.ts.map +0 -1
  13. package/dist/core/ExecutionController.js +0 -34
  14. package/dist/core/Heartbeat.d.ts +0 -13
  15. package/dist/core/Heartbeat.d.ts.map +0 -1
  16. package/dist/core/Heartbeat.js +0 -21
  17. package/dist/core/Queries.d.ts +0 -14
  18. package/dist/core/Queries.d.ts.map +0 -1
  19. package/dist/core/Queries.js +0 -31
  20. package/dist/core/Worker.d.ts +0 -21
  21. package/dist/core/Worker.d.ts.map +0 -1
  22. package/dist/core/Worker.js +0 -79
  23. package/dist/core/WorkerLifecycle.d.ts +0 -26
  24. package/dist/core/WorkerLifecycle.d.ts.map +0 -1
  25. package/dist/core/WorkerLifecycle.js +0 -69
  26. package/dist/core/WorkerState.d.ts +0 -37
  27. package/dist/core/WorkerState.d.ts.map +0 -1
  28. package/dist/core/WorkerState.js +0 -70
  29. package/dist/core/types.d.ts +0 -39
  30. package/dist/core/types.d.ts.map +0 -1
  31. package/dist/core/types.js +0 -1
  32. package/dist/flow/FlowWorkerLifecycle.d.ts +0 -26
  33. package/dist/flow/FlowWorkerLifecycle.d.ts.map +0 -1
  34. package/dist/flow/FlowWorkerLifecycle.js +0 -64
  35. package/dist/flow/StepTaskExecutor.d.ts +0 -28
  36. package/dist/flow/StepTaskExecutor.d.ts.map +0 -1
  37. package/dist/flow/StepTaskExecutor.js +0 -71
  38. package/dist/flow/StepTaskPoller.d.ts +0 -21
  39. package/dist/flow/StepTaskPoller.d.ts.map +0 -1
  40. package/dist/flow/StepTaskPoller.js +0 -34
  41. package/dist/flow/createFlowWorker.d.ts +0 -42
  42. package/dist/flow/createFlowWorker.d.ts.map +0 -1
  43. package/dist/flow/createFlowWorker.js +0 -56
  44. package/dist/flow/types.d.ts +0 -2
  45. package/dist/flow/types.d.ts.map +0 -1
  46. package/dist/flow/types.js +0 -1
  47. package/dist/index.d.ts +0 -10
  48. package/dist/index.d.ts.map +0 -1
  49. package/dist/index.js +0 -8
  50. package/dist/package.json +0 -33
  51. package/dist/platform/DenoAdapter.d.ts +0 -39
  52. package/dist/platform/DenoAdapter.d.ts.map +0 -1
  53. package/dist/platform/DenoAdapter.js +0 -126
  54. package/dist/platform/createAdapter.d.ts +0 -6
  55. package/dist/platform/createAdapter.d.ts.map +0 -1
  56. package/dist/platform/createAdapter.js +0 -16
  57. package/dist/platform/index.d.ts +0 -4
  58. package/dist/platform/index.d.ts.map +0 -1
  59. package/dist/platform/index.js +0 -3
  60. package/dist/platform/logging.d.ts +0 -10
  61. package/dist/platform/logging.d.ts.map +0 -1
  62. package/dist/platform/logging.js +0 -68
  63. package/dist/platform/types.d.ts +0 -37
  64. package/dist/platform/types.d.ts.map +0 -1
  65. package/dist/platform/types.js +0 -1
  66. package/dist/queue/MessageExecutor.d.ts +0 -43
  67. package/dist/queue/MessageExecutor.d.ts.map +0 -1
  68. package/dist/queue/MessageExecutor.js +0 -95
  69. package/dist/queue/Queue.d.ts +0 -35
  70. package/dist/queue/Queue.d.ts.map +0 -1
  71. package/dist/queue/Queue.js +0 -87
  72. package/dist/queue/ReadWithPollPoller.d.ts +0 -20
  73. package/dist/queue/ReadWithPollPoller.d.ts.map +0 -1
  74. package/dist/queue/ReadWithPollPoller.js +0 -25
  75. package/dist/queue/createQueueWorker.d.ts +0 -75
  76. package/dist/queue/createQueueWorker.d.ts.map +0 -1
  77. package/dist/queue/createQueueWorker.js +0 -47
  78. package/dist/queue/types.d.ts +0 -17
  79. package/dist/queue/types.d.ts.map +0 -1
  80. package/dist/queue/types.js +0 -1
  81. package/dist/tsconfig.lib.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgflow/edge-worker",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "license": "AGPL-3.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,11 +19,11 @@
19
19
  "dependencies": {
20
20
  "@henrygd/queue": "^1.0.7",
21
21
  "postgres": "3.4.5",
22
- "@pgflow/core": "0.1.14",
23
- "@pgflow/dsl": "0.1.14"
22
+ "@pgflow/core": "0.1.16",
23
+ "@pgflow/dsl": "0.1.16"
24
24
  },
25
25
  "devDependencies": {
26
- "@types/deno": "npm:@teidesu/deno-types@1.45.2",
26
+ "@types/deno": "^2.2.0",
27
27
  "@types/node": "~18.16.20",
28
28
  "supabase": "2.21.1"
29
29
  },
package/dist/CHANGELOG.md DELETED
@@ -1,268 +0,0 @@
1
- # @pgflow/edge-worker
2
-
3
- ## 0.1.14
4
-
5
- ### Patch Changes
6
-
7
- - 956224b: Add debug statements in EdgeWorker
8
- - @pgflow/core@0.1.14
9
- - @pgflow/dsl@0.1.14
10
-
11
- ## 0.1.13
12
-
13
- ### Patch Changes
14
-
15
- - 2a2a7bc: Add debug statements to find logger issue
16
- - @pgflow/core@0.1.13
17
- - @pgflow/dsl@0.1.13
18
-
19
- ## 0.1.12
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies [7b1328e]
24
- - @pgflow/dsl@0.1.12
25
- - @pgflow/core@0.1.12
26
-
27
- ## 0.1.11
28
-
29
- ### Patch Changes
30
-
31
- - @pgflow/core@0.1.11
32
- - @pgflow/dsl@0.1.11
33
-
34
- ## 0.1.10
35
-
36
- ### Patch Changes
37
-
38
- - bafe767: Fix deno/ folder for cli being missing
39
- - Updated dependencies [bafe767]
40
- - @pgflow/core@0.1.10
41
- - @pgflow/dsl@0.1.10
42
-
43
- ## 0.1.9
44
-
45
- ### Patch Changes
46
-
47
- - 1a30c6c: Make sure to tag and push tags
48
- - Updated dependencies [1a30c6c]
49
- - @pgflow/core@0.1.9
50
- - @pgflow/dsl@0.1.9
51
-
52
- ## 0.1.8
53
-
54
- ### Patch Changes
55
-
56
- - 05f5bd8: Update release script
57
- - Updated dependencies [05f5bd8]
58
- - @pgflow/core@0.1.8
59
- - @pgflow/dsl@0.1.8
60
-
61
- ## 0.1.7
62
-
63
- ### Patch Changes
64
-
65
- - Updated dependencies
66
- - @pgflow/core@0.1.7
67
- - @pgflow/dsl@0.1.7
68
-
69
- ## 0.1.6
70
-
71
- ### Patch Changes
72
-
73
- - Test release to verify problem with bumping edge-worker
74
- - Updated dependencies
75
- - @pgflow/core@0.1.6
76
- - @pgflow/dsl@0.1.6
77
-
78
- ## 0.1.5
79
-
80
- ### Patch Changes
81
-
82
- - 5820e7a: Bump version for tests
83
- - Updated dependencies [5820e7a]
84
- - @pgflow/core@0.1.5
85
- - @pgflow/dsl@0.1.5
86
-
87
- ## 0.1.4
88
-
89
- ### Patch Changes
90
-
91
- - @pgflow/core@0.1.4
92
- - @pgflow/dsl@0.1.4
93
-
94
- ## 0.1.3
95
-
96
- ### Patch Changes
97
-
98
- - @pgflow/core@0.1.3
99
- - @pgflow/dsl@0.1.3
100
-
101
- ## 0.1.2
102
-
103
- ### Patch Changes
104
-
105
- - @pgflow/core@0.1.2
106
- - @pgflow/dsl@0.1.2
107
-
108
- ## 0.1.1
109
-
110
- ### Patch Changes
111
-
112
- - Updated dependencies [b362364]
113
- - @pgflow/dsl@0.1.1
114
- - @pgflow/core@0.1.1
115
-
116
- ## 0.1.0
117
-
118
- ### Patch Changes
119
-
120
- - Updated dependencies [7c40238]
121
- - @pgflow/core@0.1.0
122
- - @pgflow/dsl@0.1.0
123
-
124
- ## 0.0.23
125
-
126
- ### Patch Changes
127
-
128
- - @pgflow/core@0.0.23
129
- - @pgflow/dsl@0.0.23
130
-
131
- ## 0.0.22
132
-
133
- ### Patch Changes
134
-
135
- - @pgflow/core@0.0.22
136
- - @pgflow/dsl@0.0.22
137
-
138
- ## 0.0.21
139
-
140
- ### Patch Changes
141
-
142
- - @pgflow/core@0.0.21
143
- - @pgflow/dsl@0.0.21
144
-
145
- ## 0.0.20
146
-
147
- ### Patch Changes
148
-
149
- - @pgflow/core@0.0.20
150
- - @pgflow/dsl@0.0.20
151
-
152
- ## 0.0.19
153
-
154
- ### Patch Changes
155
-
156
- - Updated dependencies [042bc64]
157
- - @pgflow/core@0.0.19
158
- - @pgflow/dsl@0.0.19
159
-
160
- ## 0.0.18
161
-
162
- ### Patch Changes
163
-
164
- - 53abf4a: Fix pnpm issues with linking to dist/
165
- - Updated dependencies [53abf4a]
166
- - @pgflow/core@0.0.18
167
- - @pgflow/dsl@0.0.18
168
-
169
- ## 0.0.17
170
-
171
- ### Patch Changes
172
-
173
- - @pgflow/core@0.0.17
174
- - @pgflow/dsl@0.0.17
175
-
176
- ## 0.0.16
177
-
178
- ### Patch Changes
179
-
180
- - @pgflow/core@0.0.16
181
- - @pgflow/dsl@0.0.16
182
-
183
- ## 0.0.15
184
-
185
- ### Patch Changes
186
-
187
- - @pgflow/core@0.0.15
188
- - @pgflow/dsl@0.0.15
189
-
190
- ## 0.0.14
191
-
192
- ### Patch Changes
193
-
194
- - @pgflow/core@0.0.14
195
- - @pgflow/dsl@0.0.14
196
-
197
- ## 0.0.13
198
-
199
- ### Patch Changes
200
-
201
- - @pgflow/core@0.0.13
202
- - @pgflow/dsl@0.0.13
203
-
204
- ## 0.0.12
205
-
206
- ### Patch Changes
207
-
208
- - @pgflow/core@0.0.12
209
- - @pgflow/dsl@0.0.12
210
-
211
- ## 0.0.11
212
-
213
- ### Patch Changes
214
-
215
- - Updated dependencies [17937e3]
216
- - @pgflow/dsl@0.0.11
217
- - @pgflow/core@0.0.11
218
-
219
- ## 0.0.10
220
-
221
- ### Patch Changes
222
-
223
- - Release again on NPM
224
- - @pgflow/core@0.0.10
225
- - @pgflow/dsl@0.0.10
226
-
227
- ## 0.0.9
228
-
229
- ### Patch Changes
230
-
231
- - 8786acf: Test jsr publish again
232
- - Updated dependencies [70d3f2d]
233
- - @pgflow/dsl@0.0.9
234
- - @pgflow/core@0.0.9
235
-
236
- ## 0.0.8
237
-
238
- ### Patch Changes
239
-
240
- - Test jsr version writing
241
- - @pgflow/core@0.0.8
242
- - @pgflow/dsl@0.0.8
243
-
244
- ## 0.0.7
245
-
246
- ### Patch Changes
247
-
248
- - 7c83db9: Add release-related options to package.json files
249
- - Updated dependencies [7c83db9]
250
- - @pgflow/core@0.0.7
251
- - @pgflow/dsl@0.0.7
252
-
253
- ## 0.0.6
254
-
255
- ### Patch Changes
256
-
257
- - 9dd4676: Update package.json configuration
258
- - @pgflow/core@0.0.6
259
- - @pgflow/dsl@0.0.6
260
-
261
- ## 0.0.5
262
-
263
- ### Patch Changes
264
-
265
- - Updated dependencies [196f7d8]
266
- - Updated dependencies [b4b0809]
267
- - @pgflow/core@0.0.5
268
- - @pgflow/dsl@0.0.5
@@ -1,121 +0,0 @@
1
- import type { Json } from './core/types.js';
2
- import { type QueueWorkerConfig } from './queue/createQueueWorker.js';
3
- import { type FlowWorkerConfig } from './flow/createFlowWorker.js';
4
- import type { PlatformAdapter } from './platform/types.js';
5
- import { MessageHandlerFn } from './queue/types.js';
6
- import type { AnyFlow } from '@pgflow/dsl';
7
- /**
8
- * Configuration options for the EdgeWorker.
9
- */
10
- export type EdgeWorkerConfig = Omit<QueueWorkerConfig, 'sql'> | Omit<FlowWorkerConfig, 'sql'>;
11
- /**
12
- * EdgeWorker is the main entry point for creating and starting edge workers.
13
- *
14
- * It provides a simple interface for starting a worker that processes messages from a queue
15
- * or executes steps in a flow.
16
- *
17
- * @example
18
- * ```typescript
19
- * // Queue worker example
20
- * import { EdgeWorker } from '@pgflow/edge-worker';
21
- *
22
- * EdgeWorker.start(async (message) => {
23
- * // Process the message
24
- * console.log('Processing message:', message);
25
- * }, {
26
- * queueName: 'my-queue',
27
- * maxConcurrent: 5,
28
- * retryLimit: 3
29
- * });
30
- *
31
- * // Flow worker example
32
- * import { EdgeWorker } from '@pgflow/edge-worker';
33
- * import { MyFlow } from './flows.js';
34
- *
35
- * EdgeWorker.start(MyFlow, {
36
- * maxConcurrent: 5
37
- * });
38
- * ```
39
- */
40
- export declare class EdgeWorker {
41
- private static platform;
42
- private static wasCalled;
43
- /**
44
- * Start the EdgeWorker with a message handler function.
45
- *
46
- * @param handler - Function that processes each message from the queue
47
- * @param config - Configuration options for the queue worker
48
- */
49
- static start<TPayload extends Json = Json>(handler: MessageHandlerFn<TPayload>, config?: Omit<QueueWorkerConfig, 'sql'>): Promise<PlatformAdapter>;
50
- /**
51
- * Start the EdgeWorker with a flow instance.
52
- *
53
- * @param flow - Flow instance that defines the workflow to execute
54
- * @param config - Configuration options for the flow worker
55
- */
56
- static start<TFlow extends AnyFlow>(flow: TFlow, config?: Omit<FlowWorkerConfig, 'sql'>): Promise<PlatformAdapter>;
57
- /**
58
- * Start the EdgeWorker with the given message handler and configuration.
59
- *
60
- * @param handler - Function that processes each message from the queue
61
- * @param config - Configuration options for the worker
62
- *
63
- * @example
64
- * ```typescript
65
- * EdgeWorker.startQueueWorker(handler, {
66
- * // name of the queue to poll for messages
67
- * queueName: 'tasks',
68
- *
69
- * // how many tasks are processed at the same time
70
- * maxConcurrent: 10,
71
- *
72
- * // how many connections to the database are opened
73
- * maxPgConnections: 4,
74
- *
75
- * // in-worker polling interval
76
- * maxPollSeconds: 5,
77
- *
78
- * // in-database polling interval
79
- * pollIntervalMs: 200,
80
- *
81
- * // how long to wait before retrying a failed job
82
- * retryDelay: 5,
83
- *
84
- * // how many times to retry a failed job
85
- * retryLimit: 5,
86
- *
87
- * // how long a job is invisible after reading
88
- * // if not successful, will reappear after this time
89
- * visibilityTimeout: 3,
90
- * });
91
- * ```
92
- */
93
- static startQueueWorker<TPayload extends Json = Json>(handler: MessageHandlerFn<TPayload>, config?: QueueWorkerConfig): Promise<PlatformAdapter>;
94
- /**
95
- * Start the EdgeWorker with the given flow instance and configuration.
96
- *
97
- * @param flow - Flow instance that defines the workflow to execute
98
- * @param config - Configuration options for the worker
99
- *
100
- * @example
101
- * ```typescript
102
- * EdgeWorker.startFlowWorker(MyFlow, {
103
- * // how many tasks are processed at the same time
104
- * maxConcurrent: 10,
105
- *
106
- * // how many connections to the database are opened
107
- * maxPgConnections: 4,
108
- *
109
- * // batch size for polling messages
110
- * batchSize: 10,
111
- * });
112
- * ```
113
- */
114
- static startFlowWorker<TFlow extends AnyFlow>(flow: TFlow, config?: FlowWorkerConfig): Promise<PlatformAdapter>;
115
- /**
116
- * Stop the EdgeWorker and clean up resources.
117
- */
118
- static stop(): Promise<void>;
119
- private static ensureFirstCall;
120
- }
121
- //# sourceMappingURL=EdgeWorker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EdgeWorker.d.ts","sourceRoot":"","sources":["../src/EdgeWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAC9B,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgC;IACvD,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IAEjC;;;;;OAKG;WACU,KAAK,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EAC7C,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACnC,MAAM,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GACtC,OAAO,CAAC,eAAe,CAAC;IAE3B;;;;;OAKG;WACU,KAAK,CAAC,KAAK,SAAS,OAAO,EACtC,IAAI,EAAE,KAAK,EACX,MAAM,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,GACrC,OAAO,CAAC,eAAe,CAAC;IAgC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;WACU,gBAAgB,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EACxD,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACnC,MAAM,GAAE,iBAAsB;IA8BhC;;;;;;;;;;;;;;;;;;;OAmBG;WACU,eAAe,CAAC,KAAK,SAAS,OAAO,EAChD,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,gBAAqB;IAyB/B;;OAEG;WACU,IAAI;IAQjB,OAAO,CAAC,MAAM,CAAC,eAAe;CAM/B"}
@@ -1,168 +0,0 @@
1
- import { createQueueWorker, } from './queue/createQueueWorker.js';
2
- import { createFlowWorker, } from './flow/createFlowWorker.js';
3
- import { createAdapter } from './platform/createAdapter.js';
4
- /**
5
- * EdgeWorker is the main entry point for creating and starting edge workers.
6
- *
7
- * It provides a simple interface for starting a worker that processes messages from a queue
8
- * or executes steps in a flow.
9
- *
10
- * @example
11
- * ```typescript
12
- * // Queue worker example
13
- * import { EdgeWorker } from '@pgflow/edge-worker';
14
- *
15
- * EdgeWorker.start(async (message) => {
16
- * // Process the message
17
- * console.log('Processing message:', message);
18
- * }, {
19
- * queueName: 'my-queue',
20
- * maxConcurrent: 5,
21
- * retryLimit: 3
22
- * });
23
- *
24
- * // Flow worker example
25
- * import { EdgeWorker } from '@pgflow/edge-worker';
26
- * import { MyFlow } from './flows.js';
27
- *
28
- * EdgeWorker.start(MyFlow, {
29
- * maxConcurrent: 5
30
- * });
31
- * ```
32
- */
33
- export class EdgeWorker {
34
- static platform = null;
35
- static wasCalled = false;
36
- /**
37
- * Implementation of the start method that handles both function and flow cases.
38
- * This method automatically detects the type of the first argument and delegates
39
- * to the appropriate worker creation method.
40
- *
41
- * @param handlerOrFlow - Either a message handler function or a Flow instance
42
- * @param config - Configuration options for the worker
43
- */
44
- static async start(handlerOrFlow, config = {}) {
45
- if (typeof handlerOrFlow === 'function') {
46
- console.log('start() if typeof handlerOrFlow is function');
47
- return this.startQueueWorker(handlerOrFlow, config);
48
- }
49
- else {
50
- console.log('start() if typeof handlerOrFlow is FLOW');
51
- return this.startFlowWorker(handlerOrFlow, config);
52
- }
53
- }
54
- /**
55
- * Start the EdgeWorker with the given message handler and configuration.
56
- *
57
- * @param handler - Function that processes each message from the queue
58
- * @param config - Configuration options for the worker
59
- *
60
- * @example
61
- * ```typescript
62
- * EdgeWorker.startQueueWorker(handler, {
63
- * // name of the queue to poll for messages
64
- * queueName: 'tasks',
65
- *
66
- * // how many tasks are processed at the same time
67
- * maxConcurrent: 10,
68
- *
69
- * // how many connections to the database are opened
70
- * maxPgConnections: 4,
71
- *
72
- * // in-worker polling interval
73
- * maxPollSeconds: 5,
74
- *
75
- * // in-database polling interval
76
- * pollIntervalMs: 200,
77
- *
78
- * // how long to wait before retrying a failed job
79
- * retryDelay: 5,
80
- *
81
- * // how many times to retry a failed job
82
- * retryLimit: 5,
83
- *
84
- * // how long a job is invisible after reading
85
- * // if not successful, will reappear after this time
86
- * visibilityTimeout: 3,
87
- * });
88
- * ```
89
- */
90
- static async startQueueWorker(handler, config = {}) {
91
- this.ensureFirstCall();
92
- // First, create the adapter
93
- this.platform = await createAdapter();
94
- // Apply default values to the config
95
- const workerConfig = {
96
- ...config,
97
- queueName: config.queueName || 'tasks',
98
- maxConcurrent: config.maxConcurrent ?? 10,
99
- maxPgConnections: config.maxPgConnections ?? 4,
100
- maxPollSeconds: config.maxPollSeconds ?? 5,
101
- pollIntervalMs: config.pollIntervalMs ?? 200,
102
- retryDelay: config.retryDelay ?? 5,
103
- retryLimit: config.retryLimit ?? 5,
104
- visibilityTimeout: config.visibilityTimeout ?? 3,
105
- connectionString: config.connectionString || this.platform.getConnectionString(),
106
- };
107
- await this.platform.startWorker((createLoggerFn) => {
108
- console.log('QUEUE: platform.startWorker callback');
109
- return createQueueWorker(handler, workerConfig, createLoggerFn);
110
- });
111
- return this.platform;
112
- }
113
- /**
114
- * Start the EdgeWorker with the given flow instance and configuration.
115
- *
116
- * @param flow - Flow instance that defines the workflow to execute
117
- * @param config - Configuration options for the worker
118
- *
119
- * @example
120
- * ```typescript
121
- * EdgeWorker.startFlowWorker(MyFlow, {
122
- * // how many tasks are processed at the same time
123
- * maxConcurrent: 10,
124
- *
125
- * // how many connections to the database are opened
126
- * maxPgConnections: 4,
127
- *
128
- * // batch size for polling messages
129
- * batchSize: 10,
130
- * });
131
- * ```
132
- */
133
- static async startFlowWorker(flow, config = {}) {
134
- this.ensureFirstCall();
135
- // First, create the adapter
136
- this.platform = await createAdapter();
137
- // Apply default values to the config
138
- const workerConfig = {
139
- ...config,
140
- maxConcurrent: config.maxConcurrent ?? 10,
141
- maxPgConnections: config.maxPgConnections ?? 4,
142
- batchSize: config.batchSize ?? 10,
143
- connectionString: config.connectionString || this.platform.getConnectionString(),
144
- };
145
- await this.platform.startWorker((createLoggerFn) => {
146
- console.log('FLOW: platform.startWorker callback');
147
- return createFlowWorker(flow, workerConfig, createLoggerFn);
148
- });
149
- return this.platform;
150
- }
151
- /**
152
- * Stop the EdgeWorker and clean up resources.
153
- */
154
- static async stop() {
155
- if (this.platform) {
156
- await this.platform.stopWorker();
157
- }
158
- else {
159
- throw new Error('EdgeWorker.start() must be called first');
160
- }
161
- }
162
- static ensureFirstCall() {
163
- if (this.wasCalled) {
164
- throw new Error('EdgeWorker worker can only be started once');
165
- }
166
- this.wasCalled = true;
167
- }
168
- }