ZH
测试版翻译

@core / jobs

1.1.0 ▾
已验证MIT
GitHub

基于 Postgres 的后台任务:持久队列、退避重试、cron 计划和无服务器 cron 端点

代码9 个文件上下文约 696 个 token扫描通过

应用 .genpmignore 后将被注入的确切目录树。固定于

src/lib/jobs/registry.ts只读 · eef017d
// Registro en memoria de tipos de tarea. Cada proceso (web y worker) importa los mismos `defineJob`.
import type { ZodType } from 'zod';

export type JobContext = {
  jobId: string;
  /** Intento actual (1 = primero). */
  attempt: number;
  /** Se aborta al vencer `timeoutMs`; pásala a fetch() y a operaciones largas. */
  signal: AbortSignal;
};

export type JobDefinition<P> = {
  type: string;
  schema: ZodType<P>;
  handler: (payload: P, ctx: JobContext) => Promise<void>;
  maxAttempts: number;
  timeoutMs: number;
};

const registry = new Map<string, JobDefinition<unknown>>();

export function registerJob<P>(def: JobDefinition<P>): void {
  if (!/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*$/.test(def.type)) throw new Error(`invalid job type: ${def.type}`);
  registry.set(def.type, def as JobDefinition<unknown>);
}

export function getJob(type: string): JobDefinition<unknown> | undefined {
  return registry.get(type);
}

/** Solo tests. */
export function clearJobs(): void {
  registry.clear();
}

举报 @core/jobs

使用 GitHub 登录后才能举报包。