@shivaedev/test-kits 0.3.0 → 0.4.0
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/README.md +83 -0
- package/dist/jobs/adapters/expireAttempt.d.ts +4 -0
- package/dist/jobs/adapters/expireAttempt.d.ts.map +1 -0
- package/dist/jobs/adapters/expireAttempt.js +17 -0
- package/dist/jobs/adapters/expireAttempt.js.map +1 -0
- package/dist/jobs/adapters/queueSignal.d.ts +7 -0
- package/dist/jobs/adapters/queueSignal.d.ts.map +1 -0
- package/dist/jobs/adapters/queueSignal.js +29 -0
- package/dist/jobs/adapters/queueSignal.js.map +1 -0
- package/dist/jobs/adapters/quotedSchema.d.ts +2 -0
- package/dist/jobs/adapters/quotedSchema.d.ts.map +1 -0
- package/dist/jobs/adapters/quotedSchema.js +4 -0
- package/dist/jobs/adapters/quotedSchema.js.map +1 -0
- package/dist/jobs/adapters/testingClient.d.ts +13 -0
- package/dist/jobs/adapters/testingClient.d.ts.map +1 -0
- package/dist/jobs/adapters/testingClient.js +99 -0
- package/dist/jobs/adapters/testingClient.js.map +1 -0
- package/dist/jobs/adapters/testingController.d.ts +80 -0
- package/dist/jobs/adapters/testingController.d.ts.map +1 -0
- package/dist/jobs/adapters/testingController.js +121 -0
- package/dist/jobs/adapters/testingController.js.map +1 -0
- package/dist/jobs/adapters/testingDueNow.d.ts +7 -0
- package/dist/jobs/adapters/testingDueNow.d.ts.map +1 -0
- package/dist/jobs/adapters/testingDueNow.js +26 -0
- package/dist/jobs/adapters/testingDueNow.js.map +1 -0
- package/dist/jobs/adapters/testingEngine.d.ts +8 -0
- package/dist/jobs/adapters/testingEngine.d.ts.map +1 -0
- package/dist/jobs/adapters/testingEngine.js +12 -0
- package/dist/jobs/adapters/testingEngine.js.map +1 -0
- package/dist/jobs/adapters/testingExpirations.d.ts +8 -0
- package/dist/jobs/adapters/testingExpirations.d.ts.map +1 -0
- package/dist/jobs/adapters/testingExpirations.js +27 -0
- package/dist/jobs/adapters/testingExpirations.js.map +1 -0
- package/dist/jobs/adapters/testingInspectionClient.d.ts +6 -0
- package/dist/jobs/adapters/testingInspectionClient.d.ts.map +1 -0
- package/dist/jobs/adapters/testingInspectionClient.js +52 -0
- package/dist/jobs/adapters/testingInspectionClient.js.map +1 -0
- package/dist/jobs/adapters/testingSignal.d.ts +12 -0
- package/dist/jobs/adapters/testingSignal.d.ts.map +1 -0
- package/dist/jobs/adapters/testingSignal.js +28 -0
- package/dist/jobs/adapters/testingSignal.js.map +1 -0
- package/dist/jobs/adapters/testingTime.d.ts +10 -0
- package/dist/jobs/adapters/testingTime.d.ts.map +1 -0
- package/dist/jobs/adapters/testingTime.js +18 -0
- package/dist/jobs/adapters/testingTime.js.map +1 -0
- package/dist/jobs/error.d.ts +22 -0
- package/dist/jobs/error.d.ts.map +1 -0
- package/dist/jobs/error.js +9 -0
- package/dist/jobs/error.js.map +1 -0
- package/dist/jobs/internal/adapters/testingFetches.d.ts +7 -0
- package/dist/jobs/internal/adapters/testingFetches.d.ts.map +1 -0
- package/dist/jobs/internal/adapters/testingFetches.js +30 -0
- package/dist/jobs/internal/adapters/testingFetches.js.map +1 -0
- package/dist/jobs/internal/testingIdle.d.ts +17 -0
- package/dist/jobs/internal/testingIdle.d.ts.map +1 -0
- package/dist/jobs/internal/testingIdle.js +18 -0
- package/dist/jobs/internal/testingIdle.js.map +1 -0
- package/dist/jobs/internal/testingOperation.d.ts +6 -0
- package/dist/jobs/internal/testingOperation.d.ts.map +1 -0
- package/dist/jobs/internal/testingOperation.js +13 -0
- package/dist/jobs/internal/testingOperation.js.map +1 -0
- package/dist/jobs/internal/testingSchedules.d.ts +14 -0
- package/dist/jobs/internal/testingSchedules.d.ts.map +1 -0
- package/dist/jobs/internal/testingSchedules.js +20 -0
- package/dist/jobs/internal/testingSchedules.js.map +1 -0
- package/dist/jobs/internal/testingWaits.d.ts +21 -0
- package/dist/jobs/internal/testingWaits.d.ts.map +1 -0
- package/dist/jobs/internal/testingWaits.js +53 -0
- package/dist/jobs/internal/testingWaits.js.map +1 -0
- package/dist/jobs/testing.d.ts +89 -0
- package/dist/jobs/testing.d.ts.map +1 -0
- package/dist/jobs/testing.js +12 -0
- package/dist/jobs/testing.js.map +1 -0
- package/package.json +16 -13
- package/src/jobs/adapters/expireAttempt.ts +27 -0
- package/src/jobs/adapters/queueSignal.ts +30 -0
- package/src/jobs/adapters/quotedSchema.ts +3 -0
- package/src/jobs/adapters/testingClient.ts +121 -0
- package/src/jobs/adapters/testingController.ts +138 -0
- package/src/jobs/adapters/testingDueNow.ts +32 -0
- package/src/jobs/adapters/testingEngine.ts +14 -0
- package/src/jobs/adapters/testingExpirations.ts +33 -0
- package/src/jobs/adapters/testingInspectionClient.ts +71 -0
- package/src/jobs/adapters/testingSignal.ts +34 -0
- package/src/jobs/adapters/testingTime.ts +25 -0
- package/src/jobs/error.ts +17 -0
- package/src/jobs/internal/adapters/testingFetches.ts +36 -0
- package/src/jobs/internal/testingIdle.ts +36 -0
- package/src/jobs/internal/testingOperation.ts +19 -0
- package/src/jobs/internal/testingSchedules.ts +35 -0
- package/src/jobs/internal/testingWaits.ts +95 -0
- package/src/jobs/testing.ts +31 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { queueSignal } from "./queueSignal.ts";
|
|
3
|
+
|
|
4
|
+
export interface InspectionSignal {
|
|
5
|
+
readonly revision: Effect.Effect<number>;
|
|
6
|
+
readonly waitForChange: (after: number) => Effect.Effect<number>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function testingSignal() {
|
|
10
|
+
const local = queueSignal();
|
|
11
|
+
let inspection: InspectionSignal | undefined;
|
|
12
|
+
const revisions = Effect.suspend(() => Effect.all([local.revision, inspection?.revision ?? Effect.succeed(0)]));
|
|
13
|
+
const revision = Effect.map(revisions, ([localRevision, inspectionRevision]) => localRevision + inspectionRevision);
|
|
14
|
+
return {
|
|
15
|
+
changed: local.changed,
|
|
16
|
+
observe: (signal: InspectionSignal) => {
|
|
17
|
+
inspection = signal;
|
|
18
|
+
},
|
|
19
|
+
revision,
|
|
20
|
+
waitForChange: (after: number) =>
|
|
21
|
+
Effect.gen(function* () {
|
|
22
|
+
const [localRevision, inspectionRevision] = yield* revisions;
|
|
23
|
+
if (localRevision + inspectionRevision !== after) {
|
|
24
|
+
return localRevision + inspectionRevision;
|
|
25
|
+
}
|
|
26
|
+
const waits = [local.waitForChange(localRevision)];
|
|
27
|
+
if (inspection !== undefined) {
|
|
28
|
+
waits.push(inspection.waitForChange(inspectionRevision));
|
|
29
|
+
}
|
|
30
|
+
yield* Effect.raceAll(waits);
|
|
31
|
+
return yield* revision;
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Duration, Effect } from "effect";
|
|
2
|
+
import type { TestClock } from "effect/testing";
|
|
3
|
+
import type { PgBossTestingError } from "#jobs/error.ts";
|
|
4
|
+
import { testingOperation } from "#jobs/internal/testingOperation.ts";
|
|
5
|
+
|
|
6
|
+
export function testingTime(
|
|
7
|
+
clock: TestClock.TestClock | undefined,
|
|
8
|
+
jobs: { readonly setTime: (time: number) => Promise<void>; readonly tick: (milliseconds: number) => Promise<void> } | undefined,
|
|
9
|
+
idle: Effect.Effect<void, PgBossTestingError>,
|
|
10
|
+
) {
|
|
11
|
+
return {
|
|
12
|
+
timePasses: (duration: Duration.Input) =>
|
|
13
|
+
Effect.gen(function* () {
|
|
14
|
+
if (clock === undefined || jobs === undefined) {
|
|
15
|
+
return yield* Effect.die(new Error("Provide the story's TestClock to makePgBossTesting before passing time"));
|
|
16
|
+
}
|
|
17
|
+
yield* idle;
|
|
18
|
+
const next = clock.currentTimeMillisUnsafe() + Duration.toMillis(Duration.fromInputUnsafe(duration));
|
|
19
|
+
yield* testingOperation("timePasses", () => jobs.setTime(next));
|
|
20
|
+
yield* clock.adjust(duration);
|
|
21
|
+
yield* testingOperation("timePasses", () => jobs.tick(0));
|
|
22
|
+
yield* idle;
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Data, Duration, type Redacted } from "effect";
|
|
2
|
+
|
|
3
|
+
export class PgBossTestingError extends Data.TaggedError("PgBossTestingError")<{
|
|
4
|
+
readonly operation: string;
|
|
5
|
+
readonly original: Redacted.Redacted<unknown>;
|
|
6
|
+
readonly queue?: string | undefined;
|
|
7
|
+
}> {}
|
|
8
|
+
|
|
9
|
+
export class PgBossWaitError extends Data.TaggedError("PgBossWaitError")<{
|
|
10
|
+
readonly lastSeen: string;
|
|
11
|
+
readonly waitingFor: string;
|
|
12
|
+
readonly within: Duration.Duration;
|
|
13
|
+
}> {
|
|
14
|
+
override get message(): string {
|
|
15
|
+
return `Gave up after ${Duration.format(this.within)} waiting until ${this.waitingFor}; last seen: ${this.lastSeen}`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ClientDatabase } from "@shivaedev/jobs/server/ClientDatabase.ts";
|
|
2
|
+
|
|
3
|
+
// pg-boss offers no hook for a worker fetch that finds nothing, so the controller recognizes its claim statement on the client's database.
|
|
4
|
+
const claim = /UPDATE\s+\S+\s+j\s+SET\s+state\s*=\s*'active'/u;
|
|
5
|
+
const claimedQueue = /\bj\.name\s*=\s*'(?<queue>[^']+)'/u;
|
|
6
|
+
|
|
7
|
+
export interface TestingFetches {
|
|
8
|
+
readonly begun: (queue: string) => number;
|
|
9
|
+
readonly passedSince: (queue: string, begun: number) => number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function testingFetches(db: ClientDatabase, changed: () => void): TestingFetches {
|
|
13
|
+
const begun = new Map<string, number>();
|
|
14
|
+
const passed = new Map<string, number[]>();
|
|
15
|
+
const executeSql = db.executeSql.bind(db);
|
|
16
|
+
db.executeSql = async (text: string, values?: unknown[]) => {
|
|
17
|
+
const queue = claim.test(text) ? claimedQueue.exec(text)?.groups?.queue : undefined;
|
|
18
|
+
if (queue === undefined) {
|
|
19
|
+
return executeSql(text, values);
|
|
20
|
+
}
|
|
21
|
+
const ordinal = (begun.get(queue) ?? 0) + 1;
|
|
22
|
+
begun.set(queue, ordinal);
|
|
23
|
+
try {
|
|
24
|
+
return await executeSql(text, values);
|
|
25
|
+
} finally {
|
|
26
|
+
const ordinals = passed.get(queue) ?? [];
|
|
27
|
+
ordinals.push(ordinal);
|
|
28
|
+
passed.set(queue, ordinals);
|
|
29
|
+
changed();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
begun: (queue) => begun.get(queue) ?? 0,
|
|
34
|
+
passedSince: (queue, mark) => (passed.get(queue) ?? []).filter((ordinal) => ordinal > mark).length,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { PgBossInspectionService } from "@shivaedev/jobs/server/inspection.ts";
|
|
3
|
+
import type { PgBossTestingError } from "#jobs/error.ts";
|
|
4
|
+
import { testingInspection } from "#jobs/internal/testingOperation.ts";
|
|
5
|
+
|
|
6
|
+
export interface TestingBatch {
|
|
7
|
+
readonly jobs: ReadonlyMap<string, number>;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
settled: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TestingWork {
|
|
13
|
+
readonly batches: Set<TestingBatch>;
|
|
14
|
+
readonly queues: Set<string>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function testingIdle(
|
|
18
|
+
inspection: () => PgBossInspectionService,
|
|
19
|
+
work: TestingWork,
|
|
20
|
+
signal: { readonly revision: Effect.Effect<number>; readonly waitForChange: (after: number) => Effect.Effect<number> },
|
|
21
|
+
wake: Effect.Effect<void> = Effect.void,
|
|
22
|
+
): Effect.Effect<void, PgBossTestingError> {
|
|
23
|
+
const busy = Effect.suspend(() => testingInspection("waitForIdle", inspection().busy([...work.queues].map((name) => ({ name })))));
|
|
24
|
+
return Effect.gen(function* () {
|
|
25
|
+
while (true) {
|
|
26
|
+
const revision = yield* signal.revision;
|
|
27
|
+
// A batch with no settlement since its fetch still holds active jobs, so it is busy without a read.
|
|
28
|
+
const unsettled = [...work.batches].some((batch) => !batch.settled);
|
|
29
|
+
if (work.queues.size === 0 || !(unsettled || (yield* busy))) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
yield* wake;
|
|
33
|
+
yield* signal.waitForChange(revision);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Effect, Redacted } from "effect";
|
|
2
|
+
import { PgBossError } from "@shivaedev/jobs/server/error.ts";
|
|
3
|
+
import { PgBossTestingError } from "#jobs/error.ts";
|
|
4
|
+
|
|
5
|
+
export function testingOperation<A>(operation: string, run: () => Promise<A>, queue?: string) {
|
|
6
|
+
return Effect.tryPromise({
|
|
7
|
+
catch: (original) => new PgBossTestingError({ operation, original: Redacted.make(original), queue }),
|
|
8
|
+
try: run,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function testingInspection<A, E, R>(operation: string, effect: Effect.Effect<A, E | PgBossError, R>, queue?: string) {
|
|
13
|
+
return effect.pipe(
|
|
14
|
+
Effect.catchIf(
|
|
15
|
+
(error): error is PgBossError => error instanceof PgBossError,
|
|
16
|
+
(error) => Effect.fail(new PgBossTestingError({ operation, original: error.original, queue: queue ?? error.queue })),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Effect, Redacted } from "effect";
|
|
2
|
+
import type { PgBossClient } from "@shivaedev/jobs/server/client.ts";
|
|
3
|
+
import type { ScheduleDefinition } from "@shivaedev/jobs/server/definition.ts";
|
|
4
|
+
import type { PgBossInspectionService } from "@shivaedev/jobs/server/inspection.ts";
|
|
5
|
+
import { PgBossTestingError } from "#jobs/error.ts";
|
|
6
|
+
import { testingInspection, testingOperation } from "#jobs/internal/testingOperation.ts";
|
|
7
|
+
|
|
8
|
+
export function testingSchedules(client: () => PgBossClient, inspection: () => PgBossInspectionService) {
|
|
9
|
+
return {
|
|
10
|
+
schedules: () =>
|
|
11
|
+
Effect.suspend(() => testingInspection("schedules", inspection().schedules())).pipe(
|
|
12
|
+
Effect.map((schedules) => schedules.map(({ name, cron, timezone }) => ({ cron, name, timezone }))),
|
|
13
|
+
),
|
|
14
|
+
trigger: (schedule: Pick<ScheduleDefinition, "name" | "scheduleOptions">) =>
|
|
15
|
+
Effect.gen(function* () {
|
|
16
|
+
const [registered] = yield* testingInspection(
|
|
17
|
+
"trigger",
|
|
18
|
+
inspection().schedules(schedule.name, schedule.scheduleOptions.key ?? ""),
|
|
19
|
+
schedule.name,
|
|
20
|
+
);
|
|
21
|
+
if (registered === undefined) {
|
|
22
|
+
return yield* new PgBossTestingError({
|
|
23
|
+
operation: "trigger",
|
|
24
|
+
original: Redacted.make(new Error("Schedule is not registered")),
|
|
25
|
+
queue: schedule.name,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return yield* testingOperation(
|
|
29
|
+
"trigger",
|
|
30
|
+
() => client().send(registered.name, registered.data, { ...registered.options, startAfter: 0 }),
|
|
31
|
+
schedule.name,
|
|
32
|
+
);
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Duration, Effect, Option, Redacted, type Schema } from "effect";
|
|
2
|
+
import type { JobPayloadSchema, QueueDefinition } from "@shivaedev/jobs/server/definition.ts";
|
|
3
|
+
import type { PgBossPayloadError } from "@shivaedev/jobs/server/error.ts";
|
|
4
|
+
import type { PgBossInspectionService } from "@shivaedev/jobs/server/inspection.ts";
|
|
5
|
+
import type { Job, JobState } from "@shivaedev/jobs/server/job.ts";
|
|
6
|
+
import { PgBossTestingError, PgBossWaitError } from "#jobs/error.ts";
|
|
7
|
+
import type { TestingFetches } from "#jobs/internal/adapters/testingFetches.ts";
|
|
8
|
+
import { testingInspection } from "#jobs/internal/testingOperation.ts";
|
|
9
|
+
import type { PgBossTestingWaitOptions } from "#jobs/testing.ts";
|
|
10
|
+
|
|
11
|
+
interface Reading<A> {
|
|
12
|
+
readonly arrived: Option.Option<A>;
|
|
13
|
+
readonly seen: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Signal {
|
|
17
|
+
readonly revision: Effect.Effect<number>;
|
|
18
|
+
readonly waitForChange: (after: number) => Effect.Effect<number>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function waitUntil<A, E, R>(
|
|
22
|
+
signal: Signal,
|
|
23
|
+
waitingFor: string,
|
|
24
|
+
read: Effect.Effect<Reading<A>, E, R>,
|
|
25
|
+
options: PgBossTestingWaitOptions | undefined,
|
|
26
|
+
) {
|
|
27
|
+
const within = Duration.fromInputUnsafe(options?.within ?? "20 seconds");
|
|
28
|
+
return Effect.suspend(() => {
|
|
29
|
+
let lastSeen = "nothing yet";
|
|
30
|
+
const wait = Effect.gen(function* () {
|
|
31
|
+
while (true) {
|
|
32
|
+
const revision = yield* signal.revision;
|
|
33
|
+
const { arrived, seen } = yield* read;
|
|
34
|
+
lastSeen = seen;
|
|
35
|
+
if (Option.isSome(arrived)) {
|
|
36
|
+
return arrived.value;
|
|
37
|
+
}
|
|
38
|
+
yield* signal.waitForChange(revision);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return wait.pipe(Effect.timeoutOrElse({ duration: within, orElse: () => Effect.fail(new PgBossWaitError({ lastSeen, waitingFor, within })) }));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function fetchesRefused(queue: Pick<QueueDefinition, "name">, original: Error) {
|
|
46
|
+
return new PgBossTestingError({ operation: "fetchesPass", original: Redacted.make(original), queue: queue.name });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function testingWaits(inspection: () => PgBossInspectionService, fetches: () => TestingFetches | undefined, signal: Signal) {
|
|
50
|
+
return {
|
|
51
|
+
fetchesPass: (queue: Pick<QueueDefinition, "name">, count: number, options?: PgBossTestingWaitOptions) =>
|
|
52
|
+
Effect.gen(function* () {
|
|
53
|
+
if (!Number.isSafeInteger(count) || count < 1) {
|
|
54
|
+
return yield* fetchesRefused(queue, new RangeError("Fetch count must be a positive integer"));
|
|
55
|
+
}
|
|
56
|
+
const observed = fetches();
|
|
57
|
+
if (observed === undefined) {
|
|
58
|
+
return yield* fetchesRefused(queue, new Error("Provide the testing clientFactory to a jobs Layer first"));
|
|
59
|
+
}
|
|
60
|
+
const begun = observed.begun(queue.name);
|
|
61
|
+
const fetchesHave = count === 1 ? "fetch that began after the wait has" : "fetches that began after the wait have";
|
|
62
|
+
return yield* waitUntil(
|
|
63
|
+
signal,
|
|
64
|
+
`${count} ${queue.name} ${fetchesHave} finished`,
|
|
65
|
+
Effect.sync(() => {
|
|
66
|
+
const passed = observed.passedSince(queue.name, begun);
|
|
67
|
+
return { arrived: passed >= count ? Option.some(undefined) : Option.none(), seen: `${passed} finished` };
|
|
68
|
+
}),
|
|
69
|
+
options,
|
|
70
|
+
);
|
|
71
|
+
}),
|
|
72
|
+
untilJob: <TName extends string, TPayload extends JobPayloadSchema | typeof Schema.Null>(
|
|
73
|
+
queue: { readonly name: TName; readonly schema: TPayload },
|
|
74
|
+
id: string,
|
|
75
|
+
state: JobState,
|
|
76
|
+
options?: PgBossTestingWaitOptions,
|
|
77
|
+
) =>
|
|
78
|
+
waitUntil(
|
|
79
|
+
signal,
|
|
80
|
+
`job ${id} in ${queue.name} is ${state}`,
|
|
81
|
+
Effect.suspend(() => testingInspection("untilJob", inspection().jobs(queue, { id }), queue.name)).pipe(
|
|
82
|
+
Effect.flatMap(([job]): Effect.Effect<Reading<Job<TPayload["Type"]>>, PgBossPayloadError, TPayload["DecodingServices"]> => {
|
|
83
|
+
if (job === undefined) {
|
|
84
|
+
return Effect.succeed({ arrived: Option.none(), seen: "no such job" });
|
|
85
|
+
}
|
|
86
|
+
if (job.state !== state) {
|
|
87
|
+
return Effect.succeed({ arrived: Option.none(), seen: job.state });
|
|
88
|
+
}
|
|
89
|
+
return Effect.succeed({ arrived: Option.some(job), seen: job.state });
|
|
90
|
+
}),
|
|
91
|
+
),
|
|
92
|
+
options,
|
|
93
|
+
),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Duration, Effect, type Tracer } from "effect";
|
|
2
|
+
import type { TestClock } from "effect/testing";
|
|
3
|
+
import { testingController } from "#jobs/adapters/testingController.ts";
|
|
4
|
+
|
|
5
|
+
export function makePgBossTesting(options: PgBossTestingOptions = {}) {
|
|
6
|
+
return testingController(options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PgBossTestingWaitOptions {
|
|
10
|
+
readonly within?: Duration.Input;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const testRetryPolicy = Object.freeze({ retryBackoff: false, retryDelay: 0 });
|
|
14
|
+
|
|
15
|
+
export interface PgBossTestingOptions {
|
|
16
|
+
readonly clock?: TestClock.TestClock;
|
|
17
|
+
readonly retryPolicy?: typeof testRetryPolicy;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function linkedWorkerSpans(sender: Pick<Tracer.AnySpan, "spanId" | "traceId">, spans: readonly Tracer.Span[]) {
|
|
21
|
+
return Effect.sync(() =>
|
|
22
|
+
spans.filter(
|
|
23
|
+
(span) =>
|
|
24
|
+
span.kind === "consumer"
|
|
25
|
+
&& span.attributes.get("messaging.system") === "pg-boss"
|
|
26
|
+
&& span.links.some((link) => link.span.spanId === sender.spanId && link.span.traceId === sender.traceId),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type PgBossTesting = ReturnType<typeof makePgBossTesting>;
|