Communitygithub.com

YepAPI/skills

使用 BullMQ/Inngest/Trigger.dev 管理队列工作器、任务重试、死信队列和并发控制。

skills 是什么?

该技能专注于在 AI 代理工作流中实现后台任务处理机制。它为将缓慢或非关键路径的任务(如发送邮件、图像处理、Webhook、报告生成和 AI 调用)转移到后台队列提供了结构化规则和代码模式。它支持多种平台:BullMQ 用于自托管的 Redis 队列,Inngest 或 Trigger.dev 用于无服务器或托管方案。关键要求包括:每个任务必须幂等(使用幂等键避免副作用),采用指数退避策略重试(3-5 次尝试,延迟 1s、10s、60s、5min),超过最大重试次数后移至死信队列(DLQ)进行人工排查而非静默丢弃。此外,还需按队列设置并发限制、保持任务负载轻量化、按优先级分离队列,并监控队列深度。文档提供了 BullMQ 和 Inngest 的实际代码示例,并明确指出应避免的模式,如在 API 请求处理程序中处理慢速任务、非幂等任务或无限并发导致资源耗尽。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/background-jobs

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

后台任务

规则

  • 将耗时任务卸载到后台作业:邮件、图片处理、Webhook、报告、AI 调用
  • BullMQ 用于自托管 Redis 队列 — Inngest 或 Trigger.dev 用于无服务器/托管方案
  • 每个任务必须幂等 — 重试时不产生副作用(使用幂等键)
  • 使用指数退避重试:3-5 次尝试,延迟时间分别为 1 秒、10 秒、60 秒、5 分钟
  • 死信队列(DLQ):超过最大重试次数后,将任务移入 DLQ 进行调查 — 绝不静默丢弃
  • 设置每个队列的并发限制 — 防止工作器过载(例如 concurrency: 5)
  • 任务负载应保持小巧:传递 ID 和引用,而非完整对象
  • 按优先级分离队列:critical(支付)、default(邮件)、low(分析)
  • 监控队列深度和处理时间 — 当队列积压时发出警报

模式

// BullMQ 模式
import { Queue, Worker } from "bullmq";
const queue = new Queue("emails", { connection: redis });

await queue.add("welcome", { userId }, {
  attempts: 3,
  backoff: { type: "exponential", delay: 1000 },
});

const worker = new Worker("emails", async (job) => {
  await sendWelcomeEmail(job.data.userId);
}, { connection: redis, concurrency: 5 });
// Inngest 无服务器模式
import { inngest } from "./client";

export const sendEmail = inngest.createFunction(
  { id: "send-welcome-email", retries: 3 },
  { event: "user/created" },
  async ({ event }) => { await sendWelcomeEmail(event.data.userId); }
);

应避免

  • 在 API 请求处理程序中处理耗时任务 — 快速响应,后台处理
  • 非幂等任务 — 重复执行会导致重复扣费、重复发送邮件
  • 无限制的并发 — 将耗尽数据库连接和内存
  • 在任务队列中存储大型负载 — 传递引用替代

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Tenant isolation (row-level vs schema), subdomain routing, per-tenant config, and data partitioning.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相关技能