import type { BaseJob } from '../../types.js'; import type { BaseAdapterOptions, SchedulePayload, FindArgs, SuccessOptions, ErrorOptions, FailureOptions, CancelOptions } from '../BaseAdapter/BaseAdapter.js'; import { BaseAdapter } from '../BaseAdapter/BaseAdapter.js'; export interface PrismaJob extends BaseJob { id: number; handler: string; /** Null once the job has completed or permanently failed */ runAt: Date | null; cron: string | null | undefined; /** Null unless the job is currently locked by a worker */ lockedAt: Date | null; /** Null unless the job is currently locked by a worker */ lockedBy: string | null; lastError: string | null; failedAt: Date | null; createdAt: Date; updatedAt: Date; } interface PrismaAdapterDelegate { findFirst(args: Record): Promise; updateMany(args: Record): Promise<{ count: number; }>; delete(args: Record): Promise; update(args: Record): Promise; create(args: Record): Promise; deleteMany(args?: Record): Promise; } interface DelegateLike { findFirst: (...args: any[]) => any; updateMany: (...args: any[]) => any; delete: (...args: any[]) => any; update: (...args: any[]) => any; create: (...args: any[]) => any; deleteMany: (...args: any[]) => any; } type DelegateKey = Extract<{ [K in keyof TDb]-?: TDb[K] extends DelegateLike ? K : never; }[keyof TDb], string>; export interface PrismaAdapterOptions extends BaseAdapterOptions { /** * An instance of PrismaClient which will be used to talk to the database. * * Typed generically so that `model` below is constrained to the model names * that actually exist in the user's schema. When the user passes their typed * db instance TypeScript infers TDb as the full generated client, giving * autocomplete on model names. `PrismaClient` is only the lower bound — in * v7 it may be a stub type, but TDb will still be inferred from the value * passed at the call site. */ db: TDb; /** * The camelCase name of the Prisma model accessor that represents the job * table, i.e. the key you'd use on `db` to query it. * * For a Prisma schema model named `BackgroundJob` this would be * `'backgroundJob'` (which is also the default). For a custom model named * `Job` this would be `'job'`. * * @default 'BackgroundJob' for now, but will be 'backgroundJob' in the next * major release. */ model?: DelegateKey | string; } /** * Implements a job adapter using Prisma ORM. * * Assumes a table exists with the following schema (the table name can be * customized): * * ```prisma * model BackgroundJob { * id Int \@id \@default(autoincrement()) * attempts Int \@default(0) * handler String * queue String * priority Int * runAt DateTime * cron String? * lockedAt DateTime? * lockedBy String? * lastError String? * failedAt DateTime? * createdAt DateTime \@default(now()) * updatedAt DateTime \@updatedAt * } * ``` */ export declare class PrismaAdapter extends BaseAdapter, Promise> { db: TDb; model: DelegateKey | string; accessor: PrismaAdapterDelegate; provider: string; constructor(options: PrismaAdapterOptions); /** * Finds the next job to run, locking it so that no other process can pick it * The act of locking a job is dependant on the DB server, so we'll run some * raw SQL to do it in each case—Prisma doesn't provide enough flexibility * in their generated code to do this in a DB-agnostic way. */ find({ processName, maxRuntime, queues, }: FindArgs): Promise; success({ job, runAt, deleteJob }: SuccessOptions): Promise; error({ job, runAt, error }: ErrorOptions): Promise; failure({ job, deleteJob, error }: FailureOptions): Promise; schedule({ name, path, args, runAt, cron, queue, priority, }: SchedulePayload): Promise; /** * Cancels a job by marking it as permanently failed so no worker will pick * it up (or retry it, if it's currently being worked on). * * If the job is currently running, the in-progress attempt is not * interrupted (the worker will stop it when `maxRuntime` is exceeded), but * it will not be retried and will not be picked up by another worker once * its lock goes stale. */ cancel({ jobId }: CancelOptions): Promise; clear(): Promise; } export {}; //# sourceMappingURL=PrismaAdapter.d.ts.map