@shivaedev/effect-pg-boss 0.2.0 → 0.2.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/CHANGELOG.md +20 -0
- package/dist/definition.d.ts +8 -8
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +6 -6
- package/dist/definition.js.map +1 -1
- package/dist/error.js +1 -1
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/client.d.ts +1 -1
- package/dist/internal/client.d.ts.map +1 -1
- package/dist/internal/health.d.ts +2 -2
- package/dist/internal/health.d.ts.map +1 -1
- package/dist/internal/health.js +3 -3
- package/dist/internal/health.js.map +1 -1
- package/dist/internal/lifecycle.d.ts +3 -3
- package/dist/internal/lifecycle.d.ts.map +1 -1
- package/dist/internal/lifecycle.js +13 -10
- package/dist/internal/lifecycle.js.map +1 -1
- package/dist/internal/register.d.ts +2 -2
- package/dist/internal/register.d.ts.map +1 -1
- package/dist/internal/register.js +14 -9
- package/dist/internal/register.js.map +1 -1
- package/dist/internal/service.d.ts +1 -1
- package/dist/internal/service.d.ts.map +1 -1
- package/dist/internal/service.js +2 -2
- package/dist/internal/service.js.map +1 -1
- package/dist/service.d.ts +1 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +4 -4
- package/dist/service.js.map +1 -1
- package/package.json +35 -29
- package/src/definition.ts +16 -16
- package/src/error.ts +1 -1
- package/src/index.ts +4 -4
- package/src/internal/client.ts +1 -1
- package/src/internal/health.ts +4 -4
- package/src/internal/lifecycle.ts +19 -13
- package/src/internal/register.ts +20 -10
- package/src/internal/service.ts +3 -3
- package/src/service.ts +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 - 2026-10-04
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Imports that leave their folder go through `#` aliases declared in the `imports` field of `package.json`: `#*.ts` resolves to `src` under the `source` condition and to `dist` otherwise, and `#test/*` names a test file. The published modules and declarations name the package's own files through these aliases.
|
|
8
|
+
|
|
9
|
+
- Validate packed consumers and executable bins through the shared workspace gate.
|
|
10
|
+
|
|
11
|
+
- Replace JSDoc blocks with a short reason comment, so the package passes the comment rules of `@shivaedev/quality`.
|
|
12
|
+
|
|
13
|
+
- Build with the `@shivaedev/quality` tsconfig presets, which target ESNext and allow only erasable TypeScript syntax.
|
|
14
|
+
|
|
15
|
+
- Type-check with TypeScript 7 only. TypeScript 6 still builds the package.
|
|
16
|
+
|
|
17
|
+
- Lint and format with the `@shivaedev/quality` Biome preset through `quality lint` at the repository root, which replaces the package's `check` script.
|
|
18
|
+
|
|
19
|
+
- Run tests through the `@shivaedev/quality` Vitest projects, which take a test's environment from its file name. Type tests are named `*.typecheck.test.ts`.
|
|
20
|
+
|
|
21
|
+
- Keep `package.json` in sort-package-json key order, checked by `quality lint`.
|
|
22
|
+
|
|
3
23
|
## 0.2.0 - 2026-09-26
|
|
4
24
|
|
|
5
25
|
### Changed
|
package/dist/definition.d.ts
CHANGED
|
@@ -5,24 +5,24 @@ export interface JobPayloadSchema extends Schema.Top {
|
|
|
5
5
|
readonly Type: object;
|
|
6
6
|
}
|
|
7
7
|
export interface JobContext {
|
|
8
|
+
readonly expireInSeconds: number;
|
|
9
|
+
readonly heartbeatSeconds: number | null;
|
|
8
10
|
readonly id: string;
|
|
9
11
|
readonly name: string;
|
|
10
12
|
readonly signal: AbortSignal;
|
|
11
|
-
readonly expireInSeconds: number;
|
|
12
|
-
readonly heartbeatSeconds: number | null;
|
|
13
13
|
}
|
|
14
14
|
export interface QueueDefinition<Name extends string = string, Payload extends JobPayloadSchema = JobPayloadSchema> {
|
|
15
15
|
readonly _tag: "QueueDefinition";
|
|
16
|
+
readonly handle: <E, R>(handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, E, R>) => QueueWorker<Payload, R>;
|
|
16
17
|
readonly name: Name;
|
|
17
|
-
readonly schema: Payload;
|
|
18
18
|
readonly queueOptions: Omit<QueueOptions, "deadLetter">;
|
|
19
|
+
readonly schema: Payload;
|
|
19
20
|
readonly workerOptions: WorkOptions;
|
|
20
|
-
readonly handle: <E, R>(handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, E, R>) => QueueWorker<Payload, R>;
|
|
21
21
|
}
|
|
22
22
|
export interface QueueWorker<Payload extends JobPayloadSchema = JobPayloadSchema, Requirements = unknown> {
|
|
23
23
|
readonly _tag: "QueueWorker";
|
|
24
|
-
readonly queue: QueueDefinition<string, Payload>;
|
|
25
24
|
readonly handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, unknown, Requirements>;
|
|
25
|
+
readonly queue: QueueDefinition<string, Payload>;
|
|
26
26
|
}
|
|
27
27
|
export interface JobRegistration {
|
|
28
28
|
readonly _tag: "QueueWorker" | "ScheduledWorker";
|
|
@@ -32,20 +32,20 @@ export interface ScheduleDefinition<Name extends string = string> {
|
|
|
32
32
|
readonly cron: string;
|
|
33
33
|
readonly name: Name;
|
|
34
34
|
readonly queueOptions: Omit<QueueOptions, "deadLetter">;
|
|
35
|
+
readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
|
|
35
36
|
readonly scheduleOptions: ScheduleOptions;
|
|
36
37
|
readonly workerOptions: WorkOptions;
|
|
37
|
-
readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
|
|
38
38
|
}
|
|
39
39
|
export interface ScheduledWorker<Requirements = unknown> {
|
|
40
40
|
readonly _tag: "ScheduledWorker";
|
|
41
|
-
readonly schedule: ScheduleDefinition;
|
|
42
41
|
readonly effect: Effect.Effect<unknown, unknown, Requirements>;
|
|
42
|
+
readonly schedule: ScheduleDefinition;
|
|
43
43
|
}
|
|
44
44
|
export type RegistrationRequirements<Registrations extends readonly JobRegistration[]> = Registrations[number] extends infer Registration ? Registration extends QueueWorker<infer Payload, infer Requirements> ? Requirements | Payload["DecodingServices"] : Registration extends ScheduledWorker<infer Requirements> ? Requirements : never : never;
|
|
45
45
|
export interface DefineQueueOptions<Name extends string, Payload extends JobPayloadSchema> {
|
|
46
46
|
readonly name: Name;
|
|
47
|
-
readonly schema: Payload;
|
|
48
47
|
readonly queue?: Omit<QueueOptions, "deadLetter">;
|
|
48
|
+
readonly schema: Payload;
|
|
49
49
|
readonly worker?: WorkOptions;
|
|
50
50
|
}
|
|
51
51
|
export declare const defineQueue: <const Name extends string, const Payload extends JobPayloadSchema>(options: DefineQueueOptions<Name, Payload>) => QueueDefinition<Name, Payload>;
|
package/dist/definition.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/E,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,GAAG;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/E,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,GAAG;IACnD,QA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
|
|
3
3
|
_tag: "QueueDefinition",
|
|
4
|
-
name: options.name,
|
|
5
|
-
queueOptions: Object.freeze({ ...options.queue }),
|
|
6
|
-
schema: options.schema,
|
|
7
|
-
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
8
4
|
handle: (handler) => Object.freeze({
|
|
9
5
|
_tag: "QueueWorker",
|
|
10
6
|
handler,
|
|
11
7
|
queue: definition,
|
|
12
8
|
}),
|
|
9
|
+
name: options.name,
|
|
10
|
+
queueOptions: Object.freeze({ ...options.queue }),
|
|
11
|
+
schema: options.schema,
|
|
12
|
+
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
13
13
|
};
|
|
14
14
|
return Object.freeze(definition);
|
|
15
15
|
};
|
|
@@ -19,13 +19,13 @@ export const defineSchedule = (options) => {
|
|
|
19
19
|
cron: options.cron,
|
|
20
20
|
name: options.name,
|
|
21
21
|
queueOptions: Object.freeze({ ...options.queue }),
|
|
22
|
-
scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
|
|
23
|
-
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
24
22
|
run: (effect) => Object.freeze({
|
|
25
23
|
_tag: "ScheduledWorker",
|
|
26
24
|
effect,
|
|
27
25
|
schedule: definition,
|
|
28
26
|
}),
|
|
27
|
+
scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
|
|
28
|
+
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
29
29
|
};
|
|
30
30
|
return Object.freeze(definition);
|
|
31
31
|
};
|
package/dist/definition.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAoEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,OAA0C,EACT,EAAE;IACnC,MAAM,UAAU,GAAmC;QAClD,IAAI,EAAE,iBAAiB;QACvB,
|
|
1
|
+
{"version":3,"file":"definition.js","sour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CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;KACjE,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAiB,EAAc,EAAE,CAAC,CAAC;IAC7D,eAAe,EAAE,GAAG,CAAC,eAAe;IACpC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;IACtC,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC"}
|
package/dist/error.js
CHANGED
|
@@ -5,7 +5,7 @@ export class PgBossPayloadError extends Data.TaggedError("PgBossPayloadError") {
|
|
|
5
5
|
}
|
|
6
6
|
export const toPgBossError = (operation, error, queue) => new PgBossError({
|
|
7
7
|
operation,
|
|
8
|
-
queue,
|
|
9
8
|
original: Redacted.make(error),
|
|
9
|
+
queue,
|
|
10
10
|
});
|
|
11
11
|
//# sourceMappingURL=error.js.map
|
package/dist/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIxC,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAI7D;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAI3E;CAAG;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAA0B,EAAE,KAAc,EAAE,KAAc,EAAe,EAAE,CACxG,IAAI,WAAW,CAAC;IACf,SAAS;IACT,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIxC,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAI7D;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAI3E;CAAG;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAA0B,EAAE,KAAc,EAAE,KAAc,EAAe,EAAE,CACxG,IAAI,WAAW,CAAC;IACf,SAAS;IACT,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IAC9B,KAAK;CACL,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export type { PgBossClient, PgBossClientFactory, } from "#internal/client.ts";
|
|
1
2
|
export { type DefineQueueOptions, type DefineScheduleOptions, defineQueue, defineSchedule, type JobContext, type JobPayloadSchema, type JobRegistration, type QueueDefinition, type QueueWorker, type ScheduleDefinition, type ScheduledWorker, } from "./definition.ts";
|
|
2
3
|
export { PgBossError, type PgBossOperation, PgBossPayloadError, } from "./error.ts";
|
|
3
4
|
export { deadLetterQueueName, type JobsHealth, type QueueHealth, } from "./health.ts";
|
|
4
|
-
export type { PgBossClient, PgBossClientFactory, } from "./internal/client.ts";
|
|
5
5
|
export { makePgBoss, type PgBossDefinition, type PgBossLayerOptions, type PgBossService, } from "./service.ts";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,WAAW,EACX,cAAc,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,KAAK,eAAe,EACpB,kBAAkB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,GAChB,MAAM,aAAa,CAAC;AACrB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,YAAY,EACZ,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,WAAW,EACX,cAAc,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,KAAK,eAAe,EACpB,kBAAkB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,WAAW,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,GAClB,MAAM,cAAc,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAGN,WAAW,EACX,cAAc,GAQd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EAEX,kBAAkB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,mBAAmB,GAGnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,UAAU,GAIV,MAAM,cAAc,CAAC"}
|
|
@@ -2,9 +2,9 @@ import type { ConstructorOptions, Job, Queue, QueueResult, ScheduleOptions, Send
|
|
|
2
2
|
export interface PgBossClient {
|
|
3
3
|
readonly createQueue: (name: string, options?: Omit<Queue, "name">) => Promise<void>;
|
|
4
4
|
readonly getQueue: (name: string) => Promise<QueueResult | null>;
|
|
5
|
+
readonly off: (event: "error", listener: (error: Error) => void) => unknown;
|
|
5
6
|
readonly offWork: (name: string) => Promise<void>;
|
|
6
7
|
readonly on: (event: "error", listener: (error: Error) => void) => unknown;
|
|
7
|
-
readonly off: (event: "error", listener: (error: Error) => void) => unknown;
|
|
8
8
|
readonly schedule: (name: string, cron: string, data?: object | null, options?: ScheduleOptions) => Promise<void>;
|
|
9
9
|
readonly send: (name: string, data?: object | null, options?: SendOptions) => Promise<string | null>;
|
|
10
10
|
readonly start: () => Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/internal/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGnI,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrF,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACjE,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/internal/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAA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IACxD,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACrI;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,YAAY,CAAC;AAEhF,eAAO,MAAM,oBAAoB,EAAE,mBAAsD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { type JobsHealth } from "
|
|
2
|
+
import { type JobsHealth } from "#health.ts";
|
|
3
3
|
import type { PgBossClient } from "./client.ts";
|
|
4
|
-
export declare const healthFor: (client: PgBossClient, names: readonly string[]) => Effect.Effect<JobsHealth, import("
|
|
4
|
+
export declare const healthFor: (client: PgBossClient, names: readonly string[]) => Effect.Effect<JobsHealth, import("#error.ts").PgBossError>;
|
|
5
5
|
//# sourceMappingURL=health.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAuB,KAAK,UAAU,EAAoB,MAAM,
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAuB,KAAK,UAAU,EAAoB,MAAM,YAAY,CAAC;AACpF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,SAAS,GAAI,QAAQ,YAAY,EAAE,OAAO,SAAS,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,WAAW,EAAE,WAAW,CA4BlI,CAAC"}
|
package/dist/internal/health.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { toPgBossError } from "
|
|
3
|
-
import { deadLetterQueueName } from "
|
|
2
|
+
import { toPgBossError } from "#error.ts";
|
|
3
|
+
import { deadLetterQueueName } from "#health.ts";
|
|
4
4
|
export const healthFor = (client, names) => Effect.forEach(names, (name) => Effect.tryPromise({
|
|
5
|
+
catch: (error) => toPgBossError("health", error, name),
|
|
5
6
|
try: async () => {
|
|
6
7
|
const [queue, deadLetter] = await Promise.all([client.getQueue(name), client.getQueue(deadLetterQueueName(name))]);
|
|
7
8
|
return {
|
|
@@ -13,7 +14,6 @@ export const healthFor = (client, names) => Effect.forEach(names, (name) => Effe
|
|
|
13
14
|
readyCount: queue?.readyCount ?? 0,
|
|
14
15
|
};
|
|
15
16
|
},
|
|
16
|
-
catch: (error) => toPgBossError("health", error, name),
|
|
17
17
|
}), { concurrency: "unbounded" }).pipe(Effect.map((jobs) => ({
|
|
18
18
|
activeTotal: jobs.reduce((sum, job) => sum + job.activeCount, 0),
|
|
19
19
|
deadLetteredTotal: jobs.reduce((sum, job) => sum + job.deadLetteredCount, 0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/internal/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAqC,MAAM,YAAY,CAAC;AAGpF,MAAM,CAAC,MAAM,SAAS,GAAG,C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EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,IAAI;IACJ,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;CAC9D,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -2,15 +2,15 @@ import { Effect } from "effect";
|
|
|
2
2
|
import type { ConstructorOptions, StopOptions } from "pg-boss";
|
|
3
3
|
import { type PgBossClient, type PgBossClientFactory } from "./client.ts";
|
|
4
4
|
export interface AcquireClientOptions {
|
|
5
|
+
readonly clientCacheKey?: string | symbol | undefined;
|
|
5
6
|
readonly clientFactory?: PgBossClientFactory | undefined;
|
|
6
7
|
readonly constructor: ConstructorOptions;
|
|
7
|
-
readonly clientCacheKey?: string | symbol | undefined;
|
|
8
8
|
}
|
|
9
9
|
export interface AcquiredClient {
|
|
10
|
-
readonly client: PgBossClient;
|
|
11
10
|
readonly cacheKey?: string | symbol;
|
|
11
|
+
readonly client: PgBossClient;
|
|
12
12
|
readonly reused: boolean;
|
|
13
13
|
}
|
|
14
|
-
export declare const acquireClient: (options: AcquireClientOptions) => Effect.Effect<AcquiredClient, import("
|
|
14
|
+
export declare const acquireClient: (options: AcquireClientOptions) => Effect.Effect<AcquiredClient, import("#error.ts").PgBossError>;
|
|
15
15
|
export declare const releaseClient: (acquired: AcquiredClient, stopOptions?: StopOptions) => Effect.Effect<void>;
|
|
16
16
|
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/internal/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EA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|
2
|
+
import { toPgBossError } from "#error.ts";
|
|
3
3
|
import { defaultClientFactory } from "./client.js";
|
|
4
4
|
const CacheKey = Symbol.for("@shivaedev/effect-pg-boss/client-cache");
|
|
5
5
|
const sharedCache = Reflect.get(globalThis, CacheKey);
|
|
6
6
|
const clientCache = sharedCache instanceof Map ? sharedCache : new Map();
|
|
7
7
|
Reflect.set(globalThis, CacheKey, clientCache);
|
|
8
|
-
const isCachedClient = (value) => typeof value === "object"
|
|
9
|
-
value !== null
|
|
10
|
-
Reflect.get(value, "client") instanceof Promise
|
|
11
|
-
typeof Reflect.get(value, "references") === "number";
|
|
8
|
+
const isCachedClient = (value) => typeof value === "object"
|
|
9
|
+
&& value !== null
|
|
10
|
+
&& Reflect.get(value, "client") instanceof Promise
|
|
11
|
+
&& typeof Reflect.get(value, "references") === "number";
|
|
12
12
|
const cachedClient = (key) => {
|
|
13
13
|
const entry = clientCache.get(key);
|
|
14
14
|
return isCachedClient(entry) ? entry : undefined;
|
|
@@ -26,6 +26,7 @@ const startClient = (options) => {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
export const acquireClient = (options) => Effect.tryPromise({
|
|
29
|
+
catch: (error) => toPgBossError("start", error),
|
|
29
30
|
try: async () => {
|
|
30
31
|
const cacheKey = options.clientCacheKey;
|
|
31
32
|
if (cacheKey === undefined) {
|
|
@@ -62,28 +63,30 @@ export const acquireClient = (options) => Effect.tryPromise({
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
catch (error) {
|
|
65
|
-
if (clientCache.get(cacheKey) === entry)
|
|
66
|
+
if (clientCache.get(cacheKey) === entry) {
|
|
66
67
|
clientCache.delete(cacheKey);
|
|
68
|
+
}
|
|
67
69
|
throw error;
|
|
68
70
|
}
|
|
69
71
|
},
|
|
70
|
-
catch: (error) => toPgBossError("start", error),
|
|
71
72
|
});
|
|
72
73
|
export const releaseClient = (acquired, stopOptions) => Effect.tryPromise({
|
|
74
|
+
catch: (error) => toPgBossError("stop", error),
|
|
73
75
|
try: async () => {
|
|
74
76
|
if (acquired.cacheKey === undefined) {
|
|
75
77
|
await acquired.client.stop(stopOptions);
|
|
76
78
|
return;
|
|
77
79
|
}
|
|
78
80
|
const entry = cachedClient(acquired.cacheKey);
|
|
79
|
-
if (entry === undefined)
|
|
81
|
+
if (entry === undefined) {
|
|
80
82
|
return;
|
|
83
|
+
}
|
|
81
84
|
entry.references -= 1;
|
|
82
|
-
if (entry.references > 0)
|
|
85
|
+
if (entry.references > 0) {
|
|
83
86
|
return;
|
|
87
|
+
}
|
|
84
88
|
clientCache.delete(acquired.cacheKey);
|
|
85
89
|
await acquired.client.stop(stopOptions);
|
|
86
90
|
},
|
|
87
|
-
catch: (error) => toPgBossError("stop", error),
|
|
88
91
|
}).pipe(Effect.catch((error) => Effect.logError(error)));
|
|
89
92
|
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/internal/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/internal/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAA+C,MAAM,aAAa,CAAC;AAOhG,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACtE,MAAM,WAAW,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC/D,MAAM,WAAW,GAAkC,WAAW,YAAY,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,EAA4B,CA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K,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC;IAC9C,GAAG,EAAE,KAAK,IAAI,EAAE;QACf,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACxC,OAAO;QACR,CAAC;QAED,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO;QACR,CAAC;QACD,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;CACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Context, Effect } from "effect";
|
|
2
|
-
import { type JobRegistration } from "
|
|
2
|
+
import { type JobRegistration } from "#definition.ts";
|
|
3
3
|
import type { PgBossClient } from "./client.ts";
|
|
4
4
|
export declare const registrationName: (registration: JobRegistration) => string;
|
|
5
5
|
export declare const registrationNames: (registrations: readonly JobRegistration[]) => readonly string[];
|
|
6
|
-
export declare const registerJobs: <R>(client: PgBossClient, registrations: readonly JobRegistration[], context: Context.Context<R>, replaceWorkers: boolean) => Effect.Effect<void, import("
|
|
6
|
+
export declare const registerJobs: <R>(client: PgBossClient, registrations: readonly JobRegistration[], context: Context.Context<R>, replaceWorkers: boolean) => Effect.Effect<void, import("#error.ts").PgBossError>;
|
|
7
7
|
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAE,KAAK,eAAe,EAAsD,MAAM,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAE,KAAK,eAAe,EAAsD,MAAM,gBAAgB,CAAC;AAG1G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD,eAAO,MAAM,gBAAgB,GAAI,cAAc,eAAe,KAAG,MAQhE,CAAC;AAqEF,eAAO,MAAM,iBAAiB,GAAI,eAAe,SAAS,eAAe,EAAE,KAAG,SAAS,MAAM,EAM5F,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAC7B,QAAQ,YAAY,EACpB,eAAe,SAAS,eAAe,EAAE,EACzC,SAAS,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAC3B,gBAAgB,OAAO,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,WAAW,CAcnD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Redacted, Schema } from "effect";
|
|
2
|
-
import { jobContext } from "
|
|
3
|
-
import { PgBossPayloadError, toPgBossError } from "
|
|
4
|
-
import { deadLetterQueueName } from "
|
|
2
|
+
import { jobContext } from "#definition.ts";
|
|
3
|
+
import { PgBossPayloadError, toPgBossError } from "#error.ts";
|
|
4
|
+
import { deadLetterQueueName } from "#health.ts";
|
|
5
5
|
const queueOptions = (options) => ({
|
|
6
6
|
retryBackoff: true,
|
|
7
7
|
retryLimit: 3,
|
|
@@ -10,10 +10,12 @@ const queueOptions = (options) => ({
|
|
|
10
10
|
const isQueueWorker = (registration) => registration._tag === "QueueWorker";
|
|
11
11
|
const isScheduledWorker = (registration) => registration._tag === "ScheduledWorker";
|
|
12
12
|
export const registrationName = (registration) => {
|
|
13
|
-
if (isQueueWorker(registration))
|
|
13
|
+
if (isQueueWorker(registration)) {
|
|
14
14
|
return registration.queue.name;
|
|
15
|
-
|
|
15
|
+
}
|
|
16
|
+
if (isScheduledWorker(registration)) {
|
|
16
17
|
return registration.schedule.name;
|
|
18
|
+
}
|
|
17
19
|
throw new TypeError(`Unknown pg-boss registration: ${registration._tag}`);
|
|
18
20
|
};
|
|
19
21
|
function workerContext(context) {
|
|
@@ -27,23 +29,26 @@ const runQueueWorker = (worker, job, context) => Effect.runPromise(Schema.decode
|
|
|
27
29
|
const registerQueue = async (client, worker, context, replaceWorker) => {
|
|
28
30
|
const name = worker.queue.name;
|
|
29
31
|
const deadLetter = deadLetterQueueName(name);
|
|
30
|
-
if (replaceWorker)
|
|
32
|
+
if (replaceWorker) {
|
|
31
33
|
await client.offWork(name);
|
|
34
|
+
}
|
|
32
35
|
await client.createQueue(deadLetter);
|
|
33
36
|
await client.createQueue(name, {
|
|
34
37
|
...queueOptions(worker.queue.queueOptions),
|
|
35
38
|
deadLetter,
|
|
36
39
|
});
|
|
37
40
|
await client.work(name, worker.queue.workerOptions, async (jobs) => {
|
|
38
|
-
for (const job of jobs)
|
|
41
|
+
for (const job of jobs) {
|
|
39
42
|
await runQueueWorker(worker, job, context);
|
|
43
|
+
}
|
|
40
44
|
});
|
|
41
45
|
};
|
|
42
46
|
const registerSchedule = async (client, worker, context, replaceWorker) => {
|
|
43
47
|
const { schedule } = worker;
|
|
44
48
|
const deadLetter = deadLetterQueueName(schedule.name);
|
|
45
|
-
if (replaceWorker)
|
|
49
|
+
if (replaceWorker) {
|
|
46
50
|
await client.offWork(schedule.name);
|
|
51
|
+
}
|
|
47
52
|
await client.createQueue(deadLetter);
|
|
48
53
|
await client.createQueue(schedule.name, {
|
|
49
54
|
...queueOptions(schedule.queueOptions),
|
|
@@ -66,6 +71,7 @@ export const registrationNames = (registrations) => {
|
|
|
66
71
|
return names;
|
|
67
72
|
};
|
|
68
73
|
export const registerJobs = (client, registrations, context, replaceWorkers) => Effect.tryPromise({
|
|
74
|
+
catch: (error) => toPgBossError("register", error),
|
|
69
75
|
try: async () => {
|
|
70
76
|
registrationNames(registrations);
|
|
71
77
|
const provided = workerContext(context);
|
|
@@ -78,6 +84,5 @@ export const registerJobs = (client, registrations, context, replaceWorkers) =>
|
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
},
|
|
81
|
-
catch: (error) => toPgBossError("register", error),
|
|
82
87
|
});
|
|
83
88
|
//# sourceMappingURL=register.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAwB,UAAU,EAA0C,MAAM,
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAwB,UAAU,EAA0C,MAAM,gBAAgB,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,MAAM,YAAY,GAAG,CAAC,OAA0C,EAAE,EAAE,CAAC,CAAC;IACrE,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,CAAC;IACb,GAAG,OAAO;CACV,CAAC,CAAC;AAEH,MAAM,aA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f,iBAAiB,CAAC,aAAa,CAAC,CAAC;QACjC,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACxC,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;YAC1C,IAAI,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;gBACjC,MAAM,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;YACrE,CAAC;iBAAM,IAAI,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC5C,MAAM,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;YACxE,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PgBossService } from "
|
|
1
|
+
import type { PgBossService } from "#service.ts";
|
|
2
2
|
import type { PgBossClient } from "./client.ts";
|
|
3
3
|
export declare const makeService: (client: PgBossClient, names: readonly string[]) => PgBossService;
|
|
4
4
|
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,eAAO,MAAM,WAAW,GAAI,QAAQ,YAAY,EAAE,OAAO,SAAS,MAAM,EAAE,KAAG,aA4B3E,CAAC"}
|
package/dist/internal/service.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Option, Redacted, Schema } from "effect";
|
|
2
|
-
import { PgBossPayloadError, toPgBossError } from "
|
|
2
|
+
import { PgBossPayloadError, toPgBossError } from "#error.ts";
|
|
3
3
|
import { healthFor } from "./health.js";
|
|
4
4
|
export const makeService = (client, names) => ({
|
|
5
5
|
enqueue: (queue, payload, options) => Schema.encodeUnknownEffect(queue.schema)(payload).pipe(Effect.mapError((error) => new PgBossPayloadError({
|
|
@@ -15,8 +15,8 @@ export const makeService = (client, names) => ({
|
|
|
15
15
|
}));
|
|
16
16
|
}
|
|
17
17
|
return Effect.tryPromise({
|
|
18
|
-
try: () => client.send(queue.name, encoded, options),
|
|
19
18
|
catch: (error) => toPgBossError("enqueue", error, queue.name),
|
|
19
|
+
try: () => client.send(queue.name, encoded, options),
|
|
20
20
|
}).pipe(Effect.map(Option.fromNullishOr));
|
|
21
21
|
})),
|
|
22
22
|
health: healthFor(client, names),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAoB,kBAAkB,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAoB,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAoB,EAAE,KAAwB,EAAiB,EAAE,CAAC,CAAC;IAC9F,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CACpC,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CACrD,MAAM,CAAC,QAAQ,CACd,CAAC,KAAK,EAAE,EAAE,CACT,IAAI,kBAAkB,CAAC;QACtB,SAAS,EAAE,QAAQ;QACnB,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,KAAK,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CACH,EACD,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAA0E,EAAE;QAClG,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrD,OAAO,MAAM,CAAC,IAAI,CACjB,IAAI,kBAAkB,CAAC;gBACtB,SAAS,EAAE,QAAQ;gBACnB,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;gBACjF,KAAK,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CACF,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,UAAU,CAAC;YACxB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC;YAC7D,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC;SACpD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CACF;IACF,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC;CAChC,CAAC,CAAC"}
|
package/dist/service.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Context, Effect, Layer, type Option, type Schema } from "effect";
|
|
2
2
|
import type { ConstructorOptions, SendOptions, StopOptions } from "pg-boss";
|
|
3
|
+
import type { PgBossClientFactory } from "#internal/client.ts";
|
|
3
4
|
import type { JobPayloadSchema, JobRegistration, QueueDefinition, RegistrationRequirements } from "./definition.ts";
|
|
4
5
|
import type { PgBossError, PgBossPayloadError } from "./error.ts";
|
|
5
6
|
import type { JobsHealth } from "./health.ts";
|
|
6
|
-
import type { PgBossClientFactory } from "./internal/client.ts";
|
|
7
7
|
export interface PgBossService {
|
|
8
8
|
readonly enqueue: <const Name extends string, const Payload extends JobPayloadSchema>(queue: QueueDefinition<Name, Payload>, payload: Schema.Schema.Type<Payload>, options?: SendOptions) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, Payload["EncodingServices"]>;
|
|
9
9
|
readonly health: Effect.Effect<JobsHealth, PgBossError>;
|
|
@@ -12,9 +12,7 @@ interface PgBossIdentifier {
|
|
|
12
12
|
readonly _pgBossIdentifier: unique symbol;
|
|
13
13
|
}
|
|
14
14
|
export type PgBossLayerOptions<Registrations extends readonly JobRegistration[], ErrorRequirements> = ConstructorOptions & {
|
|
15
|
-
/** Override client construction for compatible clients or deterministic tests. */
|
|
16
15
|
readonly clientFactory?: PgBossClientFactory;
|
|
17
|
-
/** Reuse and reference-count one started client under this key, e.g. across development module reloads. */
|
|
18
16
|
readonly clientCacheKey?: string | symbol | undefined;
|
|
19
17
|
readonly jobs: Registrations;
|
|
20
18
|
readonly onError?: (error: Error) => Effect.Effect<unknown, never, ErrorRequirements>;
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAA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Q,CAAC,iBAAiB,EAAE,OAAO,MAAM,CAAC;CAC1C;AAED,MAAM,MAAM,kBAAkB,CAAC,aAAa,SAAS,SAAS,eAAe,EAAE,EAAE,iBAAiB,IAAI,kBAAkB,GAAG;IAC1H,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAE7C,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACtF,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,aAAa,CAAC;IACzF,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,aAAa,SAAS,SAAS,eAAe,EAAE,EAAE,iBAAiB,GAAG,KAAK,EACjG,OAAO,EAAE,kBAAkB,CAAC,aAAa,EAAE,iBAAiB,CAAC,KACzD,KAAK,CAAC,KAAK,CAAC,gBAAgB,EAAE,WAAW,EAAE,wBAAwB,CAAC,aAAa,CAAC,GAAG,iBAAiB,CAAC,CAAC;CAC7G;AAID,eAAO,MAAM,UAAU,GAAI,YAAY,MAAM,KAAG,gBA6C/C,CAAC"}
|
package/dist/service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { acquireClient, releaseClient } from "
|
|
3
|
-
import { registerJobs, registrationName } from "
|
|
4
|
-
import { makeService } from "
|
|
2
|
+
import { acquireClient, releaseClient } from "#internal/lifecycle.ts";
|
|
3
|
+
import { registerJobs, registrationName } from "#internal/register.ts";
|
|
4
|
+
import { makeService } from "#internal/service.ts";
|
|
5
5
|
const logClientError = (error) => Effect.logError({ event: "pg_boss_error", message: error.message });
|
|
6
6
|
export const makePgBoss = (identifier) => {
|
|
7
7
|
const Service = Context.Service(identifier);
|
|
@@ -11,9 +11,9 @@ export const makePgBoss = (identifier) => {
|
|
|
11
11
|
const acquire = Effect.acquireRelease(Effect.gen(function* () {
|
|
12
12
|
const context = yield* Effect.context();
|
|
13
13
|
const acquired = yield* acquireClient({
|
|
14
|
+
clientCacheKey,
|
|
14
15
|
clientFactory,
|
|
15
16
|
constructor: constructorOptions,
|
|
16
|
-
clientCacheKey,
|
|
17
17
|
});
|
|
18
18
|
const reportError = onError ?? logClientError;
|
|
19
19
|
const errorListener = (error) => {
|
package/dist/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAA4B,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAA4B,MAAM,QAAQ,CAAC;AAG1E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAiCnD,MAAM,cAAc,GAAG,CAAC,KAAY,EAAuB,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AAElI,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAoB,EAAE;IAClE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAkC,UAAU,CAAC,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,CAAC;gBAC5C,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACtC,CAAC,CAAC,CACF,CAAC;QACH,CAAC,CAAC,EACF,CAAC,QAAQ,EAAE,EAAE;YACZ,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC9D,OAAO,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC,CACD,CAAC;QAEF,OAAO,KAAK,CAAC,MAAM,CAClB,OAAO,EACP,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAC1E,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/effect-pg-boss",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Effect-native jobs and lifecycle management for pg-boss",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/ShivaeDev/platform.git",
|
|
10
|
-
"directory": "packages/effect-pg-boss"
|
|
11
|
-
},
|
|
12
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/effect-pg-boss#readme",
|
|
13
6
|
"bugs": {
|
|
14
7
|
"url": "https://github.com/ShivaeDev/platform/issues"
|
|
15
8
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/ShivaeDev/platform.git",
|
|
12
|
+
"directory": "packages/effect-pg-boss"
|
|
18
13
|
},
|
|
14
|
+
"license": "MIT",
|
|
19
15
|
"sideEffects": false,
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
"type": "module",
|
|
17
|
+
"imports": {
|
|
18
|
+
"#test/*": "./test/*",
|
|
19
|
+
"#*.ts": {
|
|
20
|
+
"source": "./src/*.ts",
|
|
21
|
+
"types": "./dist/*.d.ts",
|
|
22
|
+
"default": "./dist/*.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
26
25
|
"exports": {
|
|
27
26
|
".": {
|
|
28
27
|
"types": "./dist/index.d.ts",
|
|
@@ -32,15 +31,14 @@
|
|
|
32
31
|
},
|
|
33
32
|
"./package.json": "./package.json"
|
|
34
33
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"pg-boss": "12.23.1"
|
|
42
|
-
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src",
|
|
37
|
+
"CHANGELOG.md",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
43
40
|
"devDependencies": {
|
|
41
|
+
"@shivaedev/quality": "0.7.3",
|
|
44
42
|
"@types/node": "24.10.1",
|
|
45
43
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
46
44
|
"effect": "4.0.0-rc.112",
|
|
@@ -48,13 +46,21 @@
|
|
|
48
46
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
49
47
|
"vitest": "4.1.9"
|
|
50
48
|
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"effect": "4.0.0-rc.112",
|
|
51
|
+
"pg-boss": "12.23.1"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=24"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"provenance": true
|
|
59
|
+
},
|
|
51
60
|
"scripts": {
|
|
52
61
|
"build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && tsc6 --project tsconfig.build.json",
|
|
53
|
-
"
|
|
62
|
+
"ready": "pnpm typecheck && pnpm test && pnpm build",
|
|
54
63
|
"test": "vitest run",
|
|
55
|
-
"
|
|
56
|
-
"typecheck": "tsc --noEmit",
|
|
57
|
-
"typecheck:compat": "tsc6 --noEmit",
|
|
58
|
-
"ready": "pnpm check && pnpm typecheck && pnpm typecheck:compat && pnpm test && pnpm build && pnpm test:package"
|
|
64
|
+
"typecheck": "tsc --noEmit"
|
|
59
65
|
}
|
|
60
66
|
}
|
package/src/definition.ts
CHANGED
|
@@ -7,28 +7,28 @@ export interface JobPayloadSchema extends Schema.Top {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface JobContext {
|
|
10
|
+
readonly expireInSeconds: number;
|
|
11
|
+
readonly heartbeatSeconds: number | null;
|
|
10
12
|
readonly id: string;
|
|
11
13
|
readonly name: string;
|
|
12
14
|
readonly signal: AbortSignal;
|
|
13
|
-
readonly expireInSeconds: number;
|
|
14
|
-
readonly heartbeatSeconds: number | null;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface QueueDefinition<Name extends string = string, Payload extends JobPayloadSchema = JobPayloadSchema> {
|
|
18
18
|
readonly _tag: "QueueDefinition";
|
|
19
|
-
readonly name: Name;
|
|
20
|
-
readonly schema: Payload;
|
|
21
|
-
readonly queueOptions: Omit<QueueOptions, "deadLetter">;
|
|
22
|
-
readonly workerOptions: WorkOptions;
|
|
23
19
|
readonly handle: <E, R>(
|
|
24
20
|
handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, E, R>,
|
|
25
21
|
) => QueueWorker<Payload, R>;
|
|
22
|
+
readonly name: Name;
|
|
23
|
+
readonly queueOptions: Omit<QueueOptions, "deadLetter">;
|
|
24
|
+
readonly schema: Payload;
|
|
25
|
+
readonly workerOptions: WorkOptions;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface QueueWorker<Payload extends JobPayloadSchema = JobPayloadSchema, Requirements = unknown> {
|
|
29
29
|
readonly _tag: "QueueWorker";
|
|
30
|
-
readonly queue: QueueDefinition<string, Payload>;
|
|
31
30
|
readonly handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, unknown, Requirements>;
|
|
31
|
+
readonly queue: QueueDefinition<string, Payload>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export interface JobRegistration {
|
|
@@ -40,15 +40,15 @@ export interface ScheduleDefinition<Name extends string = string> {
|
|
|
40
40
|
readonly cron: string;
|
|
41
41
|
readonly name: Name;
|
|
42
42
|
readonly queueOptions: Omit<QueueOptions, "deadLetter">;
|
|
43
|
+
readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
|
|
43
44
|
readonly scheduleOptions: ScheduleOptions;
|
|
44
45
|
readonly workerOptions: WorkOptions;
|
|
45
|
-
readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export interface ScheduledWorker<Requirements = unknown> {
|
|
49
49
|
readonly _tag: "ScheduledWorker";
|
|
50
|
-
readonly schedule: ScheduleDefinition;
|
|
51
50
|
readonly effect: Effect.Effect<unknown, unknown, Requirements>;
|
|
51
|
+
readonly schedule: ScheduleDefinition;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export type RegistrationRequirements<Registrations extends readonly JobRegistration[]> = Registrations[number] extends infer Registration
|
|
@@ -61,8 +61,8 @@ export type RegistrationRequirements<Registrations extends readonly JobRegistrat
|
|
|
61
61
|
|
|
62
62
|
export interface DefineQueueOptions<Name extends string, Payload extends JobPayloadSchema> {
|
|
63
63
|
readonly name: Name;
|
|
64
|
-
readonly schema: Payload;
|
|
65
64
|
readonly queue?: Omit<QueueOptions, "deadLetter">;
|
|
65
|
+
readonly schema: Payload;
|
|
66
66
|
readonly worker?: WorkOptions;
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -71,16 +71,16 @@ export const defineQueue = <const Name extends string, const Payload extends Job
|
|
|
71
71
|
): QueueDefinition<Name, Payload> => {
|
|
72
72
|
const definition: QueueDefinition<Name, Payload> = {
|
|
73
73
|
_tag: "QueueDefinition",
|
|
74
|
-
name: options.name,
|
|
75
|
-
queueOptions: Object.freeze({ ...options.queue }),
|
|
76
|
-
schema: options.schema,
|
|
77
|
-
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
78
74
|
handle: (handler) =>
|
|
79
75
|
Object.freeze({
|
|
80
76
|
_tag: "QueueWorker" as const,
|
|
81
77
|
handler,
|
|
82
78
|
queue: definition,
|
|
83
79
|
}),
|
|
80
|
+
name: options.name,
|
|
81
|
+
queueOptions: Object.freeze({ ...options.queue }),
|
|
82
|
+
schema: options.schema,
|
|
83
|
+
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
84
84
|
};
|
|
85
85
|
return Object.freeze(definition);
|
|
86
86
|
};
|
|
@@ -99,14 +99,14 @@ export const defineSchedule = <const Name extends string>(options: DefineSchedul
|
|
|
99
99
|
cron: options.cron,
|
|
100
100
|
name: options.name,
|
|
101
101
|
queueOptions: Object.freeze({ ...options.queue }),
|
|
102
|
-
scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
|
|
103
|
-
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
104
102
|
run: (effect) =>
|
|
105
103
|
Object.freeze({
|
|
106
104
|
_tag: "ScheduledWorker" as const,
|
|
107
105
|
effect,
|
|
108
106
|
schedule: definition,
|
|
109
107
|
}),
|
|
108
|
+
scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
|
|
109
|
+
workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
|
|
110
110
|
};
|
|
111
111
|
return Object.freeze(definition);
|
|
112
112
|
};
|
package/src/error.ts
CHANGED
|
@@ -17,6 +17,6 @@ export class PgBossPayloadError extends Data.TaggedError("PgBossPayloadError")<{
|
|
|
17
17
|
export const toPgBossError = (operation: PgBossOperation, error: unknown, queue?: string): PgBossError =>
|
|
18
18
|
new PgBossError({
|
|
19
19
|
operation,
|
|
20
|
-
queue,
|
|
21
20
|
original: Redacted.make(error),
|
|
21
|
+
queue,
|
|
22
22
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
PgBossClient,
|
|
3
|
+
PgBossClientFactory,
|
|
4
|
+
} from "#internal/client.ts";
|
|
1
5
|
export {
|
|
2
6
|
type DefineQueueOptions,
|
|
3
7
|
type DefineScheduleOptions,
|
|
@@ -21,10 +25,6 @@ export {
|
|
|
21
25
|
type JobsHealth,
|
|
22
26
|
type QueueHealth,
|
|
23
27
|
} from "./health.ts";
|
|
24
|
-
export type {
|
|
25
|
-
PgBossClient,
|
|
26
|
-
PgBossClientFactory,
|
|
27
|
-
} from "./internal/client.ts";
|
|
28
28
|
export {
|
|
29
29
|
makePgBoss,
|
|
30
30
|
type PgBossDefinition,
|
package/src/internal/client.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { PgBoss } from "pg-boss";
|
|
|
4
4
|
export interface PgBossClient {
|
|
5
5
|
readonly createQueue: (name: string, options?: Omit<Queue, "name">) => Promise<void>;
|
|
6
6
|
readonly getQueue: (name: string) => Promise<QueueResult | null>;
|
|
7
|
+
readonly off: (event: "error", listener: (error: Error) => void) => unknown;
|
|
7
8
|
readonly offWork: (name: string) => Promise<void>;
|
|
8
9
|
readonly on: (event: "error", listener: (error: Error) => void) => unknown;
|
|
9
|
-
readonly off: (event: "error", listener: (error: Error) => void) => unknown;
|
|
10
10
|
readonly schedule: (name: string, cron: string, data?: object | null, options?: ScheduleOptions) => Promise<void>;
|
|
11
11
|
readonly send: (name: string, data?: object | null, options?: SendOptions) => Promise<string | null>;
|
|
12
12
|
readonly start: () => Promise<unknown>;
|
package/src/internal/health.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { toPgBossError } from "
|
|
3
|
-
import { deadLetterQueueName, type JobsHealth, type QueueHealth } from "
|
|
2
|
+
import { toPgBossError } from "#error.ts";
|
|
3
|
+
import { deadLetterQueueName, type JobsHealth, type QueueHealth } from "#health.ts";
|
|
4
4
|
import type { PgBossClient } from "./client.ts";
|
|
5
5
|
|
|
6
|
-
export const healthFor = (client: PgBossClient, names: readonly string[]): Effect.Effect<JobsHealth, import("
|
|
6
|
+
export const healthFor = (client: PgBossClient, names: readonly string[]): Effect.Effect<JobsHealth, import("#error.ts").PgBossError> =>
|
|
7
7
|
Effect.forEach(
|
|
8
8
|
names,
|
|
9
9
|
(name) =>
|
|
10
10
|
Effect.tryPromise({
|
|
11
|
+
catch: (error) => toPgBossError("health", error, name),
|
|
11
12
|
try: async (): Promise<QueueHealth> => {
|
|
12
13
|
const [queue, deadLetter] = await Promise.all([client.getQueue(name), client.getQueue(deadLetterQueueName(name))]);
|
|
13
14
|
return {
|
|
@@ -19,7 +20,6 @@ export const healthFor = (client: PgBossClient, names: readonly string[]): Effec
|
|
|
19
20
|
readyCount: queue?.readyCount ?? 0,
|
|
20
21
|
};
|
|
21
22
|
},
|
|
22
|
-
catch: (error) => toPgBossError("health", error, name),
|
|
23
23
|
}),
|
|
24
24
|
{ concurrency: "unbounded" },
|
|
25
25
|
).pipe(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import type { ConstructorOptions, StopOptions } from "pg-boss";
|
|
3
|
-
import { toPgBossError } from "
|
|
3
|
+
import { toPgBossError } from "#error.ts";
|
|
4
4
|
import { defaultClientFactory, type PgBossClient, type PgBossClientFactory } from "./client.ts";
|
|
5
5
|
|
|
6
6
|
interface CachedClient {
|
|
@@ -14,10 +14,10 @@ const clientCache: Map<string | symbol, unknown> = sharedCache instanceof Map ?
|
|
|
14
14
|
Reflect.set(globalThis, CacheKey, clientCache);
|
|
15
15
|
|
|
16
16
|
const isCachedClient = (value: unknown): value is CachedClient =>
|
|
17
|
-
typeof value === "object"
|
|
18
|
-
value !== null
|
|
19
|
-
Reflect.get(value, "client") instanceof Promise
|
|
20
|
-
typeof Reflect.get(value, "references") === "number";
|
|
17
|
+
typeof value === "object"
|
|
18
|
+
&& value !== null
|
|
19
|
+
&& Reflect.get(value, "client") instanceof Promise
|
|
20
|
+
&& typeof Reflect.get(value, "references") === "number";
|
|
21
21
|
|
|
22
22
|
const cachedClient = (key: string | symbol): CachedClient | undefined => {
|
|
23
23
|
const entry = clientCache.get(key);
|
|
@@ -25,14 +25,14 @@ const cachedClient = (key: string | symbol): CachedClient | undefined => {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export interface AcquireClientOptions {
|
|
28
|
+
readonly clientCacheKey?: string | symbol | undefined;
|
|
28
29
|
readonly clientFactory?: PgBossClientFactory | undefined;
|
|
29
30
|
readonly constructor: ConstructorOptions;
|
|
30
|
-
readonly clientCacheKey?: string | symbol | undefined;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface AcquiredClient {
|
|
34
|
-
readonly client: PgBossClient;
|
|
35
34
|
readonly cacheKey?: string | symbol;
|
|
35
|
+
readonly client: PgBossClient;
|
|
36
36
|
readonly reused: boolean;
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -51,8 +51,9 @@ const startClient = (options: AcquireClientOptions): Promise<PgBossClient> => {
|
|
|
51
51
|
);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
export const acquireClient = (options: AcquireClientOptions): Effect.Effect<AcquiredClient, import("
|
|
54
|
+
export const acquireClient = (options: AcquireClientOptions): Effect.Effect<AcquiredClient, import("#error.ts").PgBossError> =>
|
|
55
55
|
Effect.tryPromise({
|
|
56
|
+
catch: (error) => toPgBossError("start", error),
|
|
56
57
|
try: async () => {
|
|
57
58
|
const cacheKey = options.clientCacheKey;
|
|
58
59
|
if (cacheKey === undefined) {
|
|
@@ -89,15 +90,17 @@ export const acquireClient = (options: AcquireClientOptions): Effect.Effect<Acqu
|
|
|
89
90
|
reused: false,
|
|
90
91
|
};
|
|
91
92
|
} catch (error) {
|
|
92
|
-
if (clientCache.get(cacheKey) === entry)
|
|
93
|
+
if (clientCache.get(cacheKey) === entry) {
|
|
94
|
+
clientCache.delete(cacheKey);
|
|
95
|
+
}
|
|
93
96
|
throw error;
|
|
94
97
|
}
|
|
95
98
|
},
|
|
96
|
-
catch: (error) => toPgBossError("start", error),
|
|
97
99
|
});
|
|
98
100
|
|
|
99
101
|
export const releaseClient = (acquired: AcquiredClient, stopOptions?: StopOptions): Effect.Effect<void> =>
|
|
100
102
|
Effect.tryPromise({
|
|
103
|
+
catch: (error) => toPgBossError("stop", error),
|
|
101
104
|
try: async () => {
|
|
102
105
|
if (acquired.cacheKey === undefined) {
|
|
103
106
|
await acquired.client.stop(stopOptions);
|
|
@@ -105,11 +108,14 @@ export const releaseClient = (acquired: AcquiredClient, stopOptions?: StopOption
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
const entry = cachedClient(acquired.cacheKey);
|
|
108
|
-
if (entry === undefined)
|
|
111
|
+
if (entry === undefined) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
109
114
|
entry.references -= 1;
|
|
110
|
-
if (entry.references > 0)
|
|
115
|
+
if (entry.references > 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
111
118
|
clientCache.delete(acquired.cacheKey);
|
|
112
119
|
await acquired.client.stop(stopOptions);
|
|
113
120
|
},
|
|
114
|
-
catch: (error) => toPgBossError("stop", error),
|
|
115
121
|
}).pipe(Effect.catch((error) => Effect.logError(error)));
|
package/src/internal/register.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Context, Effect, Redacted, Schema } from "effect";
|
|
2
2
|
import type { Job } from "pg-boss";
|
|
3
|
-
import { type JobRegistration, jobContext, type QueueWorker, type ScheduledWorker } from "
|
|
4
|
-
import { PgBossPayloadError, toPgBossError } from "
|
|
5
|
-
import { deadLetterQueueName } from "
|
|
3
|
+
import { type JobRegistration, jobContext, type QueueWorker, type ScheduledWorker } from "#definition.ts";
|
|
4
|
+
import { PgBossPayloadError, toPgBossError } from "#error.ts";
|
|
5
|
+
import { deadLetterQueueName } from "#health.ts";
|
|
6
6
|
import type { PgBossClient } from "./client.ts";
|
|
7
7
|
|
|
8
8
|
const queueOptions = (options: Readonly<Record<string, unknown>>) => ({
|
|
@@ -16,8 +16,12 @@ const isQueueWorker = (registration: JobRegistration): registration is QueueWork
|
|
|
16
16
|
const isScheduledWorker = (registration: JobRegistration): registration is ScheduledWorker => registration._tag === "ScheduledWorker";
|
|
17
17
|
|
|
18
18
|
export const registrationName = (registration: JobRegistration): string => {
|
|
19
|
-
if (isQueueWorker(registration))
|
|
20
|
-
|
|
19
|
+
if (isQueueWorker(registration)) {
|
|
20
|
+
return registration.queue.name;
|
|
21
|
+
}
|
|
22
|
+
if (isScheduledWorker(registration)) {
|
|
23
|
+
return registration.schedule.name;
|
|
24
|
+
}
|
|
21
25
|
throw new TypeError(`Unknown pg-boss registration: ${registration._tag}`);
|
|
22
26
|
};
|
|
23
27
|
|
|
@@ -47,14 +51,18 @@ const runQueueWorker = (worker: QueueWorker, job: Job<unknown>, context: Context
|
|
|
47
51
|
const registerQueue = async (client: PgBossClient, worker: QueueWorker, context: Context.Context<unknown>, replaceWorker: boolean): Promise<void> => {
|
|
48
52
|
const name = worker.queue.name;
|
|
49
53
|
const deadLetter = deadLetterQueueName(name);
|
|
50
|
-
if (replaceWorker)
|
|
54
|
+
if (replaceWorker) {
|
|
55
|
+
await client.offWork(name);
|
|
56
|
+
}
|
|
51
57
|
await client.createQueue(deadLetter);
|
|
52
58
|
await client.createQueue(name, {
|
|
53
59
|
...queueOptions(worker.queue.queueOptions),
|
|
54
60
|
deadLetter,
|
|
55
61
|
});
|
|
56
62
|
await client.work(name, worker.queue.workerOptions, async (jobs) => {
|
|
57
|
-
for (const job of jobs)
|
|
63
|
+
for (const job of jobs) {
|
|
64
|
+
await runQueueWorker(worker, job, context);
|
|
65
|
+
}
|
|
58
66
|
});
|
|
59
67
|
};
|
|
60
68
|
|
|
@@ -66,7 +74,9 @@ const registerSchedule = async (
|
|
|
66
74
|
): Promise<void> => {
|
|
67
75
|
const { schedule } = worker;
|
|
68
76
|
const deadLetter = deadLetterQueueName(schedule.name);
|
|
69
|
-
if (replaceWorker)
|
|
77
|
+
if (replaceWorker) {
|
|
78
|
+
await client.offWork(schedule.name);
|
|
79
|
+
}
|
|
70
80
|
await client.createQueue(deadLetter);
|
|
71
81
|
await client.createQueue(schedule.name, {
|
|
72
82
|
...queueOptions(schedule.queueOptions),
|
|
@@ -95,8 +105,9 @@ export const registerJobs = <R>(
|
|
|
95
105
|
registrations: readonly JobRegistration[],
|
|
96
106
|
context: Context.Context<R>,
|
|
97
107
|
replaceWorkers: boolean,
|
|
98
|
-
): Effect.Effect<void, import("
|
|
108
|
+
): Effect.Effect<void, import("#error.ts").PgBossError> =>
|
|
99
109
|
Effect.tryPromise({
|
|
110
|
+
catch: (error) => toPgBossError("register", error),
|
|
100
111
|
try: async () => {
|
|
101
112
|
registrationNames(registrations);
|
|
102
113
|
const provided = workerContext(context);
|
|
@@ -108,5 +119,4 @@ export const registerJobs = <R>(
|
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
121
|
},
|
|
111
|
-
catch: (error) => toPgBossError("register", error),
|
|
112
122
|
});
|
package/src/internal/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Option, Redacted, Schema } from "effect";
|
|
2
|
-
import { type PgBossError, PgBossPayloadError, toPgBossError } from "
|
|
3
|
-
import type { PgBossService } from "
|
|
2
|
+
import { type PgBossError, PgBossPayloadError, toPgBossError } from "#error.ts";
|
|
3
|
+
import type { PgBossService } from "#service.ts";
|
|
4
4
|
import type { PgBossClient } from "./client.ts";
|
|
5
5
|
import { healthFor } from "./health.ts";
|
|
6
6
|
|
|
@@ -26,8 +26,8 @@ export const makeService = (client: PgBossClient, names: readonly string[]): PgB
|
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
return Effect.tryPromise({
|
|
29
|
-
try: () => client.send(queue.name, encoded, options),
|
|
30
29
|
catch: (error) => toPgBossError("enqueue", error, queue.name),
|
|
30
|
+
try: () => client.send(queue.name, encoded, options),
|
|
31
31
|
}).pipe(Effect.map(Option.fromNullishOr));
|
|
32
32
|
}),
|
|
33
33
|
),
|
package/src/service.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Context, Effect, Layer, type Option, type Schema } from "effect";
|
|
2
2
|
import type { ConstructorOptions, SendOptions, StopOptions } from "pg-boss";
|
|
3
|
+
import type { PgBossClientFactory } from "#internal/client.ts";
|
|
4
|
+
import { acquireClient, releaseClient } from "#internal/lifecycle.ts";
|
|
5
|
+
import { registerJobs, registrationName } from "#internal/register.ts";
|
|
6
|
+
import { makeService } from "#internal/service.ts";
|
|
3
7
|
import type { JobPayloadSchema, JobRegistration, QueueDefinition, RegistrationRequirements } from "./definition.ts";
|
|
4
8
|
import type { PgBossError, PgBossPayloadError } from "./error.ts";
|
|
5
9
|
import type { JobsHealth } from "./health.ts";
|
|
6
|
-
import type { PgBossClientFactory } from "./internal/client.ts";
|
|
7
|
-
import { acquireClient, releaseClient } from "./internal/lifecycle.ts";
|
|
8
|
-
import { registerJobs, registrationName } from "./internal/register.ts";
|
|
9
|
-
import { makeService } from "./internal/service.ts";
|
|
10
10
|
|
|
11
11
|
export interface PgBossService {
|
|
12
12
|
readonly enqueue: <const Name extends string, const Payload extends JobPayloadSchema>(
|
|
@@ -22,9 +22,8 @@ interface PgBossIdentifier {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export type PgBossLayerOptions<Registrations extends readonly JobRegistration[], ErrorRequirements> = ConstructorOptions & {
|
|
25
|
-
/** Override client construction for compatible clients or deterministic tests. */
|
|
26
25
|
readonly clientFactory?: PgBossClientFactory;
|
|
27
|
-
|
|
26
|
+
// One started client is reference-counted per key, so development module reloads reuse it instead of starting another.
|
|
28
27
|
readonly clientCacheKey?: string | symbol | undefined;
|
|
29
28
|
readonly jobs: Registrations;
|
|
30
29
|
readonly onError?: (error: Error) => Effect.Effect<unknown, never, ErrorRequirements>;
|
|
@@ -53,9 +52,9 @@ export const makePgBoss = (identifier: string): PgBossDefinition => {
|
|
|
53
52
|
Effect.gen(function* () {
|
|
54
53
|
const context = yield* Effect.context<Requirements>();
|
|
55
54
|
const acquired = yield* acquireClient({
|
|
55
|
+
clientCacheKey,
|
|
56
56
|
clientFactory,
|
|
57
57
|
constructor: constructorOptions,
|
|
58
|
-
clientCacheKey,
|
|
59
58
|
});
|
|
60
59
|
const reportError: (error: Error) => Effect.Effect<unknown, never, Requirements> = onError ?? logClientError;
|
|
61
60
|
const errorListener = (error: Error) => {
|