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