Communitygithub.com

YepAPI/skills

使用 BullMQ / Inngest / Trigger.dev 管理背景工作佇列,包含工作重試、死信佇列與並發控制。

skills 是什麼?

此技能專注於在開發工具中導入背景工作(Background Jobs)的最佳實踐,支援 BullMQ(自託管 Redis 佇列)與 Inngest 或 Trigger.dev(無伺服器/託管方案)。它強制所有工作必須具備冪等性(Idempotent),並使用指數退避重試策略(3-5 次嘗試,延遲 1 秒、10 秒、60 秒、5 分鐘),超過最大重試次數後自動移至死信佇列(DLQ)以便調查,絕不靜默丟棄。技能要求按佇列設定並發限制(如 concurrency: 5),避免工作者過載,並建議將佇列依優先級分為 critical(付款)、default(郵件)、low(分析)。工作負載應保持輕量,僅傳遞 ID 與參考值,而非完整物件。同時應監控佇列深度與處理時間,並在佇列積壓時發出警報。開發者需避免在 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.

相關技能