inngest について
inngestは、Inngestでイベント駆動ワークフローと永続実行型のサーバーレスバックグラウンドジョブを構築するスキルです。開発者が複数ステップ、スケジュール実行、Webhook起点の関数を設計し、リトライ、並行数制御、冪等性を設定できます。
主な機能
- 01イベント起点の関数設計
- 02永続実行型の複数ステップワークフロー
- 03リトライと並行数制御の設定
- 04スケジュール関数と遅延ステップ
- 05ファンアウトと冪等性パターン
- 06よくある実装上の問題の確認
活用シーン
- 01複数ステップにわたる注文処理
- 02重複排除を伴うWebhook処理
- 03定期レポートやクリーンアップの実行
- 04長時間のAI処理パイプラインの構築
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ pedronauck/ skills --skill inngestインストール後、Claude Code で/inngestを入力して読み込まれたか確認します。
詳細
Inngest 統合
サーバーレスファーストのバックグラウンドジョブ、イベント駆動型ワークフロー、そしてキューやワーカーを管理せずに実現する耐久性のある実行のための Inngest エキスパートです。
原則
- イベントが基本要素 - すべてはキューではなくイベントからトリガーされます
- ステップはチェックポイント - 各ステップの結果は耐久性をもって保存されます
- スリープはハックではありません - Inngest のスリープは本物であり、スレッドをブロックしません
- リトライは自動 - ただしポリシーはあなたが制御します
- 関数は単なる HTTP ハンドラー - HTTP を提供できる場所ならどこでもデプロイできます
- 並行性は最重要の関心事 - ダウンストリームのサービスを保護します
- 冪等性キーは重複を防ぎます - 重要な操作には必ず使用してください
- ファンアウトは組み込み - 1 つのイベントで多数の関数をトリガーできます
機能
- inngest-functions
- event-driven-workflows
- step-functions
- serverless-background-jobs
- durable-sleep
- fan-out-patterns
- concurrency-control
- scheduled-functions
スコープ
- redis-queues -> bullmq-specialist
- serverless-queues -> upstash-qstash
- workflow-orchestration -> temporal-craftsman
- message-streaming -> event-architect
- infrastructure -> infra-architect
ツール
コア
- inngest
- inngest-cli
フレームワーク
- nextjs
- express
- hono
- remix
- sveltekit
デプロイ
- vercel
- cloudflare-workers
- netlify
- railway
- fly-io
パターン
- step-functions
- event-fan-out
- scheduled-cron
- webhook-handling
パターン
基本的な関数のセットアップ
Next.js で型付きイベントを使用する Inngest 関数
使用するタイミング: 任意の Next.js プロジェクトで Inngest を始めるとき
// lib/inngest/client.ts import { Inngest } from 'inngest';
export const inngest = new Inngest({ id: 'my-app', schemas: new EventSchemas().fromRecord(), });
// Define your events with types type Events = { 'user/signed.up': { data: { userId: string; email: string } }; 'order/placed': { data: { orderId: string; total: number } }; };
// lib/inngest/functions.ts import { inngest } from './client';
export const sendWelcomeEmail = inngest.createFunction( { id: 'send-welcome-email' }, { event: 'user/signed.up' }, async ({ event, step }) => { // Step 1: Get user details const user = await step.run('get-user', async () => { return await db.users.findUnique({ where: { id: event.data.userId } }); });
// Step 2: Send welcome email
await step.run('send-email', async () => {
await resend.emails.send({
to: user.email,
subject: 'Welcome!',
template: 'welcome',
});
});
// Step 3: Wait 24 hours, then send tips
await step.sleep('wait-for-tips', '24h');
await step.run('send-tips', async () => {
await resend.emails.send({
to: user.email,
subject: 'Getting Started Tips',
template: 'tips',
});
});
} );
// app/api/inngest/route.ts (Next.js App Router) import { serve } from 'inngest/next'; import { inngest } from '@/lib/inngest/client'; import { sendWelcomeEmail } from '@/lib/inngest/functions';
export const { GET, POST, PUT } = serve({ client: inngest, functions: [sendWelcomeEmail], });
マルチステップワークフロー
並列ステップとエラーハンドリングを備えた複雑なワークフロー
使用する場面: 複数のサービスや長時間の待機を伴う処理
export const processOrder = inngest.createFunction( { id: 'process-order', retries: 3, concurrency: { limit: 10 }, // 同時に処理する注文は最大10件 }, { event: 'order/placed' }, async ({ event, step }) => { const { orderId } = event.data;
// 並列ステップ - 両方が同時に実行されます
const [inventory, payment] = await Promise.all([
step.run('check-inventory', () => checkInventory(orderId)),
step.run('validate-payment', () => validatePayment(orderId)),
]);
if (!inventory.available) {
// 直接呼び出す代わりにイベントを送信します(ファンアウトパターン)
await step.sendEvent('notify-backorder', {
name: 'order/backordered',
data: { orderId, items: inventory.missing },
});
return { status: 'backordered' };
}
// 支払いを処理します
const charge = await step.run('charge-payment', async () => {
return await stripe.charges.create({
amount: event.data.total,
customer: payment.customerId,
});
});
// 注文を発送します
await step.run('ship-order', () => fulfillment.ship(orderId));
return { status: 'completed', chargeId: charge.id };
} );
スケジュール/Cron 関数
スケジュールに従って実行される関数
使用する場面: 日次レポートやクリーンアップジョブなどの定期的なタスク
export const dailyDigest = inngest.createFunction( { id: 'daily-digest' }, { cron: '0 9 * * *' }, // 毎日 UTC 9時 async ({ step }) => { // ダイジェストを希望するすべてのユーザーを取得します const users = await step.run('get-users', async () => { return await db.users.findMany({ where: { digestEnabled: true }, }); });
// 各ユーザーに送信します(子イベントを作成します)
await step.sendEvent(
'send-digests',
users.map(user => ({
name: 'digest/send',
data: { userId: user.id },
}))
);
return { sent: users.length };
} );
// 個別のダイジェスト送信を処理する別の関数 export const sendDigest = inngest.createFunction( { id: 'send-digest', concurrency: { limit: 50 } }, { event: 'digest/send' }, async ({ event, step }) => { // ... 個別のダイジェストを送信します } );
冪等性を備えた Webhook ハンドラー
重複排除により Webhook を安全に処理します
使用する場面: Stripe、GitHub、その他の Webhook を処理する場合
export const handleStripeWebhook = inngest.createFunction( { id: 'stripe-webhook', // Stripe イベント ID による重複排除 idempotency: 'event.data.stripeEventId', }, { event: 'stripe/webhook.received' }, async ({ event, step }) => { const { type, data } = event.data;
switch (type) {
case 'checkout.session.completed':
await step.run('fulfill-order', async () => {
await fulfillOrder(data.session.id);
});
break;
case 'customer.subscription.deleted':
await step.run('cancel-subscription', async () => {
await cancelSubscription(data.subscription.id);
});
break;
}
} );
長時間処理を伴う AI パイプライン
チャンク単位の処理によるマルチステップ AI 処理
使用する場面: 完了までに数分かかる可能性がある AI ワークフロー
export const processDocument = inngest.createFunction( { id: 'process-document', retries: 2, concurrency: { limit: 5 }, // API 使用量を制限 }, { event: 'document/uploaded' }, async ({ event, step }) => { // ステップ 1: テキストを抽出(時間がかかる場合があります) const text = await step.run('extract-text', async () => { return await extractTextFromPDF(event.data.fileUrl); });
// ステップ 2: 埋め込み用にチャンク化
const chunks = await step.run('chunk-text', async () => {
return chunkText(text, { maxTokens: 500 });
});
// ステップ 3: 埋め込みを生成(API レート制限あり)
const embeddings = await step.run('generate-embeddings', async () => {
return await openai.embeddings.create({
model: 'text-embedding-3-small',
input: chunks,
});
});
// ステップ 4: ベクトル DB に保存
await step.run('store-vectors', async () => {
await vectorDb.upsert({
vectors: embeddings.data.map((e, i) => ({
id: `${event.data.documentId}-${i}`,
values: e.embedding,
metadata: { chunk: chunks[i] },
})),
});
});
return { chunks: chunks.length, status: 'indexed' };
} );
検証チェック
Inngest の serve ハンドラーが存在する
Severity: CRITICAL
Message: Inngest はイベントを受信するために serve ハンドラーが必要です
Fix action: serve() をエクスポートする app/api/inngest/route.ts を作成してください
関数が serve に登録されている
Severity: ERROR
Message: すべての Inngest 関数が serve() 呼び出しに登録されていることを確認してください
Fix action: serve() 内の functions 配列に関数を追加してください
step.run に説明的な名前がある
Severity: WARNING
Message: ステップ名はケバブケースで説明的であるべきです
Fix action: 'fetch-user' や 'send-email' のような説明的なステップ名を使用してください
waitForEvent にタイムアウトがある
Severity: ERROR
Message: waitForEvent には無限待機を防ぐためのタイムアウトが必要です
Fix action: timeout オプションを追加してください: { timeout: '24h' }
関数に同時実行制限がある
Severity: WARNING
Message: ダウンストリームサービスを保護するために同時実行制限の追加を検討してください
Fix action: 関数設定に concurrency: { limit: 10 } を追加してください
イベント型が定義されている
Severity: WARNING
Message: Inngest クライアントは型安全性のためにイベントスキーマを定義すべきです
Fix action: schemas: new EventSchemas().fromRecord() を追加してください
関数に一意の ID がある
Severity: CRITICAL
Message: すべての Inngest 関数には一意の ID が必要です
Fix action: 関数設定に id: 'my-function-name' を追加してください
Sleep が期間文字列を使用している
Severity: WARNING
Message: step.sleep はミリ秒ではなく '1h' や '30m' のような期間文字列を使用すべきです
Fix action: 期間文字列を使用してください: step.sleep('wait', '1h')
リトライポリシーが設定されている
Severity: WARNING
Message: 障害処理のためにリトライポリシーの設定を検討してください
Fix action: retries: 3 または retries: { attempts: 3, backoff: { ... } } を追加してください
決済関数の冪等性キー
Severity: ERROR
Message: 決済関連の関数は冪等性キーを使用すべきです
Fix action: 関数設定に idempotency: 'event.data.orderId' を追加してください
コラボレーション
委任トリガー
- redis|queue infrastructure|bullmq -> bullmq-specialist (既存インフラストラクチャで Redis ベースのキューが必要)
- serverless queue|http queue|scheduled http -> upstash-qstash (イベントフレームワークなしでプレーン HTTP 配信と cron が必要)
- saga|compensation|rollback|long-running workflow -> temporal-craftsman (補償を伴う複雑なワークフローオーケストレーションが必要)
- event sourcing|event store|cqrs -> event-architect (イベントソーシングパターンが必要)
- vercel|deploy|production -> vercel-deployment (デプロイ設定が必要)
- database|schema|data model -> supabase-backend (イベントデータ用のデータベースが必要)
- api|endpoint|route -> backend (イベントをトリガーする API が必要)
Vercel バックグラウンドジョブ
スキル: inngest, nextjs-app-router, vercel-deployment
ワークフロー:
1. Define Inngest functions (inngest)
2. Set up serve handler in Next.js (nextjs-app-router)
3. Configure function timeouts (vercel-deployment)
4. Deploy and test (vercel-deployment)
AI パイプライン
スキル: inngest, ai-agents-architect, supabase-backend
ワークフロー:
1. Design AI workflow steps (ai-agents-architect)
2. Implement with Inngest durability (inngest)
3. Store results in database (supabase-backend)
4. Handle retries for API failures (inngest)
Webhook 処理
スキル: inngest, stripe-integration, backend
ワークフロー:
1. Receive webhook (backend)
2. Send to Inngest with idempotency (inngest)
3. Process payment logic (stripe-integration)
4. Update application state (backend)
メール自動化
スキル: inngest, email-systems, supabase-backend
ワークフロー:
1. Trigger event from user action (inngest)
2. Schedule drip emails with step.sleep (inngest)
3. Send emails with retry (email-systems)
4. Track email status (supabase-backend)
スケジュールタスク
スキル: inngest, backend, analytics-architecture
ワークフロー:
1. Define cron triggers (inngest)
2. Implement processing logic (backend)
3. Aggregate and report data (analytics-architecture)
4. Handle failures with alerting (inngest)
関連スキル
相性の良いスキル: nextjs-app-router, vercel-deployment, supabase-backend, email-systems, ai-agents-architect, stripe-integration
使用する場面
- ユーザーが言及または示唆した場合: inngest
- ユーザーが言及または示唆した場合: サーバーレスバックグラウンドジョブ
- ユーザーが言及または示唆した場合: イベント駆動型ワークフロー
- ユーザーが言及または示唆した場合: ステップ関数
- ユーザーが言及または示唆した場合: 耐久性のある実行
- ユーザーが言及または示唆した場合: Vercel バックグラウンドジョブ
- ユーザーが言及または示唆した場合: スケジュール関数
- ユーザーが言及または示唆した場合: ファンアウト
制限事項
- このスキルは、タスクが上記の範囲に明確に一致する場合にのみ使用してください。
- 出力を、環境固有の検証、テスト、または専門家によるレビューの代替として扱わないでください。
- 必要な入力、権限、安全境界、または成功基準が欠けている場合は、停止して確認を求めてください。