@pgflow/edge-worker 0.0.19 → 0.0.20
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/CHANGELOG.md +102 -0
- package/dist/EdgeWorker.d.ts +74 -0
- package/dist/EdgeWorker.d.ts.map +1 -0
- package/dist/EdgeWorker.js +98 -0
- package/dist/LICENSE.md +660 -0
- package/dist/README.md +46 -0
- package/dist/core/BatchProcessor.d.ts +13 -0
- package/dist/core/BatchProcessor.d.ts.map +1 -0
- package/dist/core/BatchProcessor.js +29 -0
- package/dist/core/ExecutionController.d.ts +15 -0
- package/dist/core/ExecutionController.d.ts.map +1 -0
- package/dist/core/ExecutionController.js +34 -0
- package/dist/core/Heartbeat.d.ts +13 -0
- package/dist/core/Heartbeat.d.ts.map +1 -0
- package/dist/core/Heartbeat.js +21 -0
- package/dist/core/Queries.d.ts +14 -0
- package/dist/core/Queries.d.ts.map +1 -0
- package/dist/core/Queries.js +31 -0
- package/dist/core/Worker.d.ts +21 -0
- package/dist/core/Worker.d.ts.map +1 -0
- package/dist/core/Worker.js +79 -0
- package/dist/core/WorkerLifecycle.d.ts +26 -0
- package/dist/core/WorkerLifecycle.d.ts.map +1 -0
- package/dist/core/WorkerLifecycle.js +69 -0
- package/dist/core/WorkerState.d.ts +37 -0
- package/dist/core/WorkerState.d.ts.map +1 -0
- package/dist/core/WorkerState.js +70 -0
- package/dist/core/types.d.ts +39 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +1 -0
- package/dist/flow/FlowWorkerLifecycle.d.ts +26 -0
- package/dist/flow/FlowWorkerLifecycle.d.ts.map +1 -0
- package/dist/flow/FlowWorkerLifecycle.js +64 -0
- package/dist/flow/StepTaskExecutor.d.ts +28 -0
- package/dist/flow/StepTaskExecutor.d.ts.map +1 -0
- package/dist/flow/StepTaskExecutor.js +71 -0
- package/dist/flow/StepTaskPoller.d.ts +21 -0
- package/dist/flow/StepTaskPoller.d.ts.map +1 -0
- package/dist/flow/StepTaskPoller.js +34 -0
- package/dist/flow/createFlowWorker.d.ts +24 -0
- package/dist/flow/createFlowWorker.d.ts.map +1 -0
- package/dist/flow/createFlowWorker.js +56 -0
- package/dist/flow/types.d.ts +2 -0
- package/dist/flow/types.d.ts.map +1 -0
- package/dist/flow/types.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/package.json +34 -0
- package/dist/platform/DenoAdapter.d.ts +39 -0
- package/dist/platform/DenoAdapter.d.ts.map +1 -0
- package/dist/platform/DenoAdapter.js +123 -0
- package/dist/platform/createAdapter.d.ts +6 -0
- package/dist/platform/createAdapter.d.ts.map +1 -0
- package/dist/platform/createAdapter.js +16 -0
- package/dist/platform/index.d.ts +4 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +3 -0
- package/dist/platform/logging.d.ts +10 -0
- package/dist/platform/logging.d.ts.map +1 -0
- package/dist/platform/logging.js +65 -0
- package/dist/platform/types.d.ts +37 -0
- package/dist/platform/types.d.ts.map +1 -0
- package/dist/platform/types.js +1 -0
- package/dist/queue/MessageExecutor.d.ts +43 -0
- package/dist/queue/MessageExecutor.d.ts.map +1 -0
- package/dist/queue/MessageExecutor.js +95 -0
- package/dist/queue/Queue.d.ts +35 -0
- package/dist/queue/Queue.d.ts.map +1 -0
- package/dist/queue/Queue.js +87 -0
- package/dist/queue/ReadWithPollPoller.d.ts +20 -0
- package/dist/queue/ReadWithPollPoller.d.ts.map +1 -0
- package/dist/queue/ReadWithPollPoller.js +25 -0
- package/dist/queue/createQueueWorker.d.ts +75 -0
- package/dist/queue/createQueueWorker.d.ts.map +1 -0
- package/dist/queue/createQueueWorker.js +47 -0
- package/dist/queue/types.d.ts +17 -0
- package/dist/queue/types.d.ts.map +1 -0
- package/dist/queue/types.js +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @pgflow/edge-worker
|
|
2
|
+
|
|
3
|
+
## 0.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pgflow/core@0.0.17
|
|
8
|
+
- @pgflow/dsl@0.0.17
|
|
9
|
+
|
|
10
|
+
## 0.0.16
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- @pgflow/core@0.0.16
|
|
15
|
+
- @pgflow/dsl@0.0.16
|
|
16
|
+
|
|
17
|
+
## 0.0.15
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- @pgflow/core@0.0.15
|
|
22
|
+
- @pgflow/dsl@0.0.15
|
|
23
|
+
|
|
24
|
+
## 0.0.14
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- @pgflow/core@0.0.14
|
|
29
|
+
- @pgflow/dsl@0.0.14
|
|
30
|
+
|
|
31
|
+
## 0.0.13
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- @pgflow/core@0.0.13
|
|
36
|
+
- @pgflow/dsl@0.0.13
|
|
37
|
+
|
|
38
|
+
## 0.0.12
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- @pgflow/core@0.0.12
|
|
43
|
+
- @pgflow/dsl@0.0.12
|
|
44
|
+
|
|
45
|
+
## 0.0.11
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [17937e3]
|
|
50
|
+
- @pgflow/dsl@0.0.11
|
|
51
|
+
- @pgflow/core@0.0.11
|
|
52
|
+
|
|
53
|
+
## 0.0.10
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Release again on NPM
|
|
58
|
+
- @pgflow/core@0.0.10
|
|
59
|
+
- @pgflow/dsl@0.0.10
|
|
60
|
+
|
|
61
|
+
## 0.0.9
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- 8786acf: Test jsr publish again
|
|
66
|
+
- Updated dependencies [70d3f2d]
|
|
67
|
+
- @pgflow/dsl@0.0.9
|
|
68
|
+
- @pgflow/core@0.0.9
|
|
69
|
+
|
|
70
|
+
## 0.0.8
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- Test jsr version writing
|
|
75
|
+
- @pgflow/core@0.0.8
|
|
76
|
+
- @pgflow/dsl@0.0.8
|
|
77
|
+
|
|
78
|
+
## 0.0.7
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- 7c83db9: Add release-related options to package.json files
|
|
83
|
+
- Updated dependencies [7c83db9]
|
|
84
|
+
- @pgflow/core@0.0.7
|
|
85
|
+
- @pgflow/dsl@0.0.7
|
|
86
|
+
|
|
87
|
+
## 0.0.6
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- 9dd4676: Update package.json configuration
|
|
92
|
+
- @pgflow/core@0.0.6
|
|
93
|
+
- @pgflow/dsl@0.0.6
|
|
94
|
+
|
|
95
|
+
## 0.0.5
|
|
96
|
+
|
|
97
|
+
### Patch Changes
|
|
98
|
+
|
|
99
|
+
- Updated dependencies [196f7d8]
|
|
100
|
+
- Updated dependencies [b4b0809]
|
|
101
|
+
- @pgflow/core@0.0.5
|
|
102
|
+
- @pgflow/dsl@0.0.5
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Json } from './core/types.js';
|
|
2
|
+
import { type QueueWorkerConfig } from './queue/createQueueWorker.js';
|
|
3
|
+
import type { PlatformAdapter } from './platform/types.js';
|
|
4
|
+
import { MessageHandlerFn } from './queue/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the EdgeWorker.
|
|
7
|
+
*/
|
|
8
|
+
export type EdgeWorkerConfig = QueueWorkerConfig;
|
|
9
|
+
/**
|
|
10
|
+
* EdgeWorker is the main entry point for creating and starting edge workers.
|
|
11
|
+
*
|
|
12
|
+
* It provides a simple interface for starting a worker that processes messages from a queue.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { EdgeWorker } from '@pgflow/edge-worker';
|
|
17
|
+
*
|
|
18
|
+
* EdgeWorker.start(async (message) => {
|
|
19
|
+
* // Process the message
|
|
20
|
+
* console.log('Processing message:', message);
|
|
21
|
+
* }, {
|
|
22
|
+
* queueName: 'my-queue',
|
|
23
|
+
* maxConcurrent: 5,
|
|
24
|
+
* retryLimit: 3
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class EdgeWorker {
|
|
29
|
+
private static platform;
|
|
30
|
+
private static wasCalled;
|
|
31
|
+
/**
|
|
32
|
+
* Start the EdgeWorker with the given message handler and configuration.
|
|
33
|
+
*
|
|
34
|
+
* @param handler - Function that processes each message from the queue
|
|
35
|
+
* @param config - Configuration options for the worker
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* EdgeWorker.start(handler, {
|
|
40
|
+
* // name of the queue to poll for messages
|
|
41
|
+
* queueName: 'tasks',
|
|
42
|
+
*
|
|
43
|
+
* // how many tasks are processed at the same time
|
|
44
|
+
* maxConcurrent: 10,
|
|
45
|
+
*
|
|
46
|
+
* // how many connections to the database are opened
|
|
47
|
+
* maxPgConnections: 4,
|
|
48
|
+
*
|
|
49
|
+
* // in-worker polling interval
|
|
50
|
+
* maxPollSeconds: 5,
|
|
51
|
+
*
|
|
52
|
+
* // in-database polling interval
|
|
53
|
+
* pollIntervalMs: 200,
|
|
54
|
+
*
|
|
55
|
+
* // how long to wait before retrying a failed job
|
|
56
|
+
* retryDelay: 5,
|
|
57
|
+
*
|
|
58
|
+
* // how many times to retry a failed job
|
|
59
|
+
* retryLimit: 5,
|
|
60
|
+
*
|
|
61
|
+
* // how long a job is invisible after reading
|
|
62
|
+
* // if not successful, will reappear after this time
|
|
63
|
+
* visibilityTimeout: 3,
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static start<TPayload extends Json = Json>(handler: MessageHandlerFn<TPayload>, config?: EdgeWorkerConfig): Promise<PlatformAdapter>;
|
|
68
|
+
/**
|
|
69
|
+
* Stop the EdgeWorker and clean up resources.
|
|
70
|
+
*/
|
|
71
|
+
static stop(): Promise<void>;
|
|
72
|
+
private static ensureFirstCall;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=EdgeWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgC;IACvD,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;WACU,KAAK,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EAC7C,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACnC,MAAM,GAAE,gBAAqB;IA6B/B;;OAEG;WACU,IAAI;IAQjB,OAAO,CAAC,MAAM,CAAC,eAAe;CAM/B"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createQueueWorker, } from './queue/createQueueWorker.js';
|
|
2
|
+
import { createAdapter } from './platform/createAdapter.js';
|
|
3
|
+
/**
|
|
4
|
+
* EdgeWorker is the main entry point for creating and starting edge workers.
|
|
5
|
+
*
|
|
6
|
+
* It provides a simple interface for starting a worker that processes messages from a queue.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { EdgeWorker } from '@pgflow/edge-worker';
|
|
11
|
+
*
|
|
12
|
+
* EdgeWorker.start(async (message) => {
|
|
13
|
+
* // Process the message
|
|
14
|
+
* console.log('Processing message:', message);
|
|
15
|
+
* }, {
|
|
16
|
+
* queueName: 'my-queue',
|
|
17
|
+
* maxConcurrent: 5,
|
|
18
|
+
* retryLimit: 3
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class EdgeWorker {
|
|
23
|
+
static platform = null;
|
|
24
|
+
static wasCalled = false;
|
|
25
|
+
/**
|
|
26
|
+
* Start the EdgeWorker with the given message handler and configuration.
|
|
27
|
+
*
|
|
28
|
+
* @param handler - Function that processes each message from the queue
|
|
29
|
+
* @param config - Configuration options for the worker
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* EdgeWorker.start(handler, {
|
|
34
|
+
* // name of the queue to poll for messages
|
|
35
|
+
* queueName: 'tasks',
|
|
36
|
+
*
|
|
37
|
+
* // how many tasks are processed at the same time
|
|
38
|
+
* maxConcurrent: 10,
|
|
39
|
+
*
|
|
40
|
+
* // how many connections to the database are opened
|
|
41
|
+
* maxPgConnections: 4,
|
|
42
|
+
*
|
|
43
|
+
* // in-worker polling interval
|
|
44
|
+
* maxPollSeconds: 5,
|
|
45
|
+
*
|
|
46
|
+
* // in-database polling interval
|
|
47
|
+
* pollIntervalMs: 200,
|
|
48
|
+
*
|
|
49
|
+
* // how long to wait before retrying a failed job
|
|
50
|
+
* retryDelay: 5,
|
|
51
|
+
*
|
|
52
|
+
* // how many times to retry a failed job
|
|
53
|
+
* retryLimit: 5,
|
|
54
|
+
*
|
|
55
|
+
* // how long a job is invisible after reading
|
|
56
|
+
* // if not successful, will reappear after this time
|
|
57
|
+
* visibilityTimeout: 3,
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static async start(handler, config = {}) {
|
|
62
|
+
this.ensureFirstCall();
|
|
63
|
+
// First, create the adapter
|
|
64
|
+
this.platform = await createAdapter();
|
|
65
|
+
// Apply default values to the config
|
|
66
|
+
const workerConfig = {
|
|
67
|
+
...config,
|
|
68
|
+
queueName: config.queueName || 'tasks',
|
|
69
|
+
maxConcurrent: config.maxConcurrent ?? 10,
|
|
70
|
+
maxPgConnections: config.maxPgConnections ?? 4,
|
|
71
|
+
maxPollSeconds: config.maxPollSeconds ?? 5,
|
|
72
|
+
pollIntervalMs: config.pollIntervalMs ?? 200,
|
|
73
|
+
retryDelay: config.retryDelay ?? 5,
|
|
74
|
+
retryLimit: config.retryLimit ?? 5,
|
|
75
|
+
visibilityTimeout: config.visibilityTimeout ?? 3,
|
|
76
|
+
connectionString: config.connectionString || this.platform.getConnectionString(),
|
|
77
|
+
};
|
|
78
|
+
await this.platform.startWorker((createLoggerFn) => createQueueWorker(handler, workerConfig, createLoggerFn));
|
|
79
|
+
return this.platform;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Stop the EdgeWorker and clean up resources.
|
|
83
|
+
*/
|
|
84
|
+
static async stop() {
|
|
85
|
+
if (this.platform) {
|
|
86
|
+
await this.platform.stopWorker();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error('EdgeWorker.start() must be called first');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
static ensureFirstCall() {
|
|
93
|
+
if (this.wasCalled) {
|
|
94
|
+
throw new Error('EdgeWorker.start() can only be called once');
|
|
95
|
+
}
|
|
96
|
+
this.wasCalled = true;
|
|
97
|
+
}
|
|
98
|
+
}
|