feat: make queues durable by default and add seed helpers
This commit is contained in:
@@ -5,11 +5,13 @@ import {
|
||||
type DurableQueueOptions,
|
||||
type QueueHealth,
|
||||
} from "./durable.ts";
|
||||
import { configuredQueueStore } from "./configured.ts";
|
||||
|
||||
export type JobStatus = "queued" | "completed" | "failed" | "cancelled" | "missing";
|
||||
|
||||
export interface DefinedJobOptions<T> extends Omit<AddOptions, "idempotencyKey"> {
|
||||
run: (data: T, context: JobContext & { job: Job<T> }) => void | Promise<void>;
|
||||
success?: (data: T, job: Job<T>) => void | Promise<void>;
|
||||
failed?: (data: T, error: unknown, job: Job<T>) => void | Promise<void>;
|
||||
idempotency?: (data: T) => string | undefined;
|
||||
validate?: (data: unknown) => data is T;
|
||||
@@ -65,6 +67,7 @@ export function defineQueue<TJobs extends QueueJobDefinitions>(
|
||||
definition.queue ??
|
||||
createDurableQueue({
|
||||
...definition.options,
|
||||
store: definition.options?.store ?? configuredQueueStore(),
|
||||
async onDeadLetter(job, error) {
|
||||
await definition.options?.onDeadLetter?.(job, error);
|
||||
const prefix = `${name}:`;
|
||||
@@ -82,6 +85,7 @@ export function defineQueue<TJobs extends QueueJobDefinitions>(
|
||||
throw new TypeError(`WRN-QUEUE-PAYLOAD: invalid payload for '${jobName}'`);
|
||||
}
|
||||
await jobDefinition.run(job.data, { ...context, job });
|
||||
await jobDefinition.success?.(job.data, job);
|
||||
};
|
||||
queue.process(jobName, handler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user