@pgflow/edge-worker 0.0.9 → 0.0.10-prealpha.1
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/EdgeWorker.d.ts +73 -0
- package/dist/EdgeWorker.d.ts.map +1 -0
- package/dist/EdgeWorker.js +105 -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 -953
- package/dist/package.json +33 -0
- package/dist/platform/DenoAdapter.d.ts +23 -0
- package/dist/platform/DenoAdapter.d.ts.map +1 -0
- package/dist/platform/DenoAdapter.js +132 -0
- package/dist/platform/createAdapter.d.ts +7 -0
- package/dist/platform/createAdapter.d.ts.map +1 -0
- package/dist/platform/createAdapter.js +17 -0
- package/dist/platform/deno-types.d.ts +13 -0
- package/dist/platform/deno-types.d.ts.map +1 -0
- package/dist/platform/deno-types.js +6 -0
- package/dist/platform/index.d.ts +5 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +4 -0
- package/dist/platform/types.d.ts +45 -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 +74 -0
- package/dist/queue/createQueueWorker.d.ts.map +1 -0
- package/dist/queue/createQueueWorker.js +47 -0
- package/dist/queue/types.d.ts +13 -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 +15 -4
- package/dist/CHANGELOG.md +0 -44
- package/dist/LICENSE.md +0 -660
- package/dist/README.md +0 -46
- package/dist/index.js.map +0 -7
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Json } from '../core/types.js';
|
|
2
|
+
import { Worker } from '../core/Worker.js';
|
|
3
|
+
import postgres from 'postgres';
|
|
4
|
+
import type { Logger } from '../platform/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the queue worker
|
|
7
|
+
*/
|
|
8
|
+
export type QueueWorkerConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* PostgreSQL connection string.
|
|
11
|
+
* If not provided, it will be read from the EDGE_WORKER_DB_URL environment variable.
|
|
12
|
+
*/
|
|
13
|
+
connectionString?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Name of the queue to poll for messages
|
|
16
|
+
* @default 'tasks'
|
|
17
|
+
*/
|
|
18
|
+
queueName?: string;
|
|
19
|
+
/**
|
|
20
|
+
* How many tasks are processed at the same time
|
|
21
|
+
* @default 10
|
|
22
|
+
*/
|
|
23
|
+
maxConcurrent?: number;
|
|
24
|
+
/**
|
|
25
|
+
* How many connections to the database are opened
|
|
26
|
+
* @default 4
|
|
27
|
+
*/
|
|
28
|
+
maxPgConnections?: number;
|
|
29
|
+
/**
|
|
30
|
+
* In-worker polling interval in seconds
|
|
31
|
+
* @default 5
|
|
32
|
+
*/
|
|
33
|
+
maxPollSeconds?: number;
|
|
34
|
+
/**
|
|
35
|
+
* In-database polling interval in milliseconds
|
|
36
|
+
* @default 200
|
|
37
|
+
*/
|
|
38
|
+
pollIntervalMs?: number;
|
|
39
|
+
/**
|
|
40
|
+
* How long to wait before retrying a failed job in seconds
|
|
41
|
+
* @default 5
|
|
42
|
+
*/
|
|
43
|
+
retryDelay?: number;
|
|
44
|
+
/**
|
|
45
|
+
* How many times to retry a failed job
|
|
46
|
+
* @default 5
|
|
47
|
+
*/
|
|
48
|
+
retryLimit?: number;
|
|
49
|
+
/**
|
|
50
|
+
* How long a job is invisible after reading in seconds.
|
|
51
|
+
* If not successful, will reappear after this time.
|
|
52
|
+
* @default 3
|
|
53
|
+
*/
|
|
54
|
+
visibilityTimeout?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Batch size for polling messages
|
|
57
|
+
* @default 10
|
|
58
|
+
*/
|
|
59
|
+
batchSize?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Optional SQL client instance
|
|
62
|
+
*/
|
|
63
|
+
sql?: postgres.Sql;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new Worker instance for processing queue messages.
|
|
67
|
+
*
|
|
68
|
+
* @param handler - The message handler function that processes each message from the queue
|
|
69
|
+
* @param config - Configuration options for the worker
|
|
70
|
+
* @param createLogger - Function to create loggers for different components
|
|
71
|
+
* @returns A configured Worker instance ready to be started
|
|
72
|
+
*/
|
|
73
|
+
export declare function createQueueWorker<TPayload extends Json>(handler: (message: TPayload) => Promise<void> | void, config: QueueWorkerConfig, createLogger: (module: string) => Logger): Worker;
|
|
74
|
+
//# sourceMappingURL=createQueueWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueueWorker.d.ts","sourceRoot":"","sources":["../../src/queue/createQueueWorker.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC;CACpB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,IAAI,EACrD,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EACpD,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GACvC,MAAM,CA8ER"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ExecutionController } from '../core/ExecutionController.js';
|
|
2
|
+
import { MessageExecutor } from './MessageExecutor.js';
|
|
3
|
+
import { Queries } from '../core/Queries.js';
|
|
4
|
+
import { Queue } from './Queue.js';
|
|
5
|
+
import { ReadWithPollPoller } from './ReadWithPollPoller.js';
|
|
6
|
+
import { Worker } from '../core/Worker.js';
|
|
7
|
+
import postgres from 'postgres';
|
|
8
|
+
import { WorkerLifecycle } from '../core/WorkerLifecycle.js';
|
|
9
|
+
import { BatchProcessor } from '../core/BatchProcessor.js';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new Worker instance for processing queue messages.
|
|
12
|
+
*
|
|
13
|
+
* @param handler - The message handler function that processes each message from the queue
|
|
14
|
+
* @param config - Configuration options for the worker
|
|
15
|
+
* @param createLogger - Function to create loggers for different components
|
|
16
|
+
* @returns A configured Worker instance ready to be started
|
|
17
|
+
*/
|
|
18
|
+
export function createQueueWorker(handler, config, createLogger) {
|
|
19
|
+
// Create component-specific loggers
|
|
20
|
+
const logger = createLogger('QueueWorker');
|
|
21
|
+
logger.info(`Creating queue worker for ${config.queueName || 'tasks'}`);
|
|
22
|
+
const abortController = new AbortController();
|
|
23
|
+
const abortSignal = abortController.signal;
|
|
24
|
+
// Use provided SQL connection if available, otherwise create one from connection string
|
|
25
|
+
const sql = config.sql ||
|
|
26
|
+
postgres(config.connectionString || '', {
|
|
27
|
+
max: config.maxPgConnections,
|
|
28
|
+
prepare: false,
|
|
29
|
+
});
|
|
30
|
+
const queue = new Queue(sql, config.queueName || 'tasks', createLogger('Queue'));
|
|
31
|
+
const queries = new Queries(sql);
|
|
32
|
+
const lifecycle = new WorkerLifecycle(queries, queue, createLogger('WorkerLifecycle'));
|
|
33
|
+
const executorFactory = (record, signal) => {
|
|
34
|
+
return new MessageExecutor(queue, record, handler, signal, config.retryLimit || 5, config.retryDelay || 3, createLogger('MessageExecutor'));
|
|
35
|
+
};
|
|
36
|
+
const poller = new ReadWithPollPoller(queue, abortSignal, {
|
|
37
|
+
batchSize: config.batchSize || config.maxConcurrent || 10,
|
|
38
|
+
maxPollSeconds: config.maxPollSeconds || 5,
|
|
39
|
+
pollIntervalMs: config.pollIntervalMs || 200,
|
|
40
|
+
visibilityTimeout: config.visibilityTimeout || 3,
|
|
41
|
+
}, createLogger('ReadWithPollPoller'));
|
|
42
|
+
const executionController = new ExecutionController(executorFactory, abortSignal, {
|
|
43
|
+
maxConcurrent: config.maxConcurrent || 10,
|
|
44
|
+
}, createLogger('ExecutionController'));
|
|
45
|
+
const batchProcessor = new BatchProcessor(executionController, poller, abortSignal, createLogger('BatchProcessor'));
|
|
46
|
+
return new Worker(batchProcessor, lifecycle, sql, createLogger('Worker'));
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Json, IMessage } from '../core/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fields are nullable because types in postgres does not allow NOT NULL,
|
|
4
|
+
* but all those values except `message` come from queue table columns,
|
|
5
|
+
* which are explicitely marked as NOT NULL.
|
|
6
|
+
*/
|
|
7
|
+
export interface PgmqMessageRecord<TPayload extends Json | null = Json> extends IMessage {
|
|
8
|
+
read_ct: number;
|
|
9
|
+
enqueued_at: string;
|
|
10
|
+
vt: string;
|
|
11
|
+
message: TPayload;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/queue/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,GAAG,IAAI,CACpE,SAAQ,QAAQ;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,QAAQ,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.6.3"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgflow/edge-worker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10-prealpha.1",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"files": [
|
|
10
17
|
"dist"
|
|
11
18
|
],
|
|
12
19
|
"dependencies": {
|
|
13
20
|
"@henrygd/queue": "^1.0.7",
|
|
21
|
+
"@pgflow/core": "workspace:*",
|
|
22
|
+
"@pgflow/dsl": "workspace:*",
|
|
14
23
|
"pino": "^9.6.0",
|
|
15
|
-
"postgres": "3.4.5"
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
"postgres": "3.4.5"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@teidesu/deno-types": "1.42.4",
|
|
28
|
+
"supabase": "2.21.1"
|
|
18
29
|
},
|
|
19
30
|
"publishConfig": {
|
|
20
31
|
"access": "public"
|
package/dist/CHANGELOG.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# @pgflow/edge-worker
|
|
2
|
-
|
|
3
|
-
## 0.0.9
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 8786acf: Test jsr publish again
|
|
8
|
-
- Updated dependencies [70d3f2d]
|
|
9
|
-
- @pgflow/dsl@0.0.9
|
|
10
|
-
- @pgflow/core@0.0.9
|
|
11
|
-
|
|
12
|
-
## 0.0.8
|
|
13
|
-
|
|
14
|
-
### Patch Changes
|
|
15
|
-
|
|
16
|
-
- Test jsr version writing
|
|
17
|
-
- @pgflow/core@0.0.8
|
|
18
|
-
- @pgflow/dsl@0.0.8
|
|
19
|
-
|
|
20
|
-
## 0.0.7
|
|
21
|
-
|
|
22
|
-
### Patch Changes
|
|
23
|
-
|
|
24
|
-
- 7c83db9: Add release-related options to package.json files
|
|
25
|
-
- Updated dependencies [7c83db9]
|
|
26
|
-
- @pgflow/core@0.0.7
|
|
27
|
-
- @pgflow/dsl@0.0.7
|
|
28
|
-
|
|
29
|
-
## 0.0.6
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- 9dd4676: Update package.json configuration
|
|
34
|
-
- @pgflow/core@0.0.6
|
|
35
|
-
- @pgflow/dsl@0.0.6
|
|
36
|
-
|
|
37
|
-
## 0.0.5
|
|
38
|
-
|
|
39
|
-
### Patch Changes
|
|
40
|
-
|
|
41
|
-
- Updated dependencies [196f7d8]
|
|
42
|
-
- Updated dependencies [b4b0809]
|
|
43
|
-
- @pgflow/core@0.0.5
|
|
44
|
-
- @pgflow/dsl@0.0.5
|