Communitygithub.com

バックグラウンドジョブキュー

BullMQ、Inngest、Trigger.devを使用したジョブキュー、リトライ、デッドレターキュー、同時実行制御の実装を支援するスキルです。

バックグラウンドジョブキュー とは?

このスキルは、バックグラウンドジョブ処理に関するベストプラクティスと具体的な実装パターンを提供します。メール送信、画像処理、Webhook、レポート生成、AI APIコールなどの低速な処理をAPIリクエストハンドラから切り離し、バックグラウンドで非同期に実行するためのルールとコード例が含まれています。主にBullMQ(自己管理Redisキュー)、Inngest、Trigger.dev(サーバーレス/マネージドキュー)の3つのプラットフォームをサポートし、それぞれに対応した実装パターン(TypeScriptコード付き)を提供します。ジョブの冪等性保証、指数バックオフによるリトライ(最大3~5回)、デッドレターキューへの自動移動、キュー単位の同時実行制限(例:concurrency: 5)、ペイロードサイズの最小化(IDや参照のみを渡す)、優先度別のキュー分割(critical/default/low)といった重要な設計原則をカバーしています。さらに、キュー深度と処理時間の監視によるアラート設定も推奨しており、本番環境で信頼性の高いジョブ処理システムを構築するためのガイドラインを提供します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/background-jobs

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

バックグラウンドジョブ

ルール

  • 低速な処理はバックグラウンドジョブにオフロードする:メール、画像処理、Webhook、レポート、AI APIコール
  • 自己管理のRedisキューにはBullMQ — サーバーレス/マネージドには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.

関連スキル