Bell キュー・Cron 処理
Bell サービスは RPC メソッドに加えて、Queue Consumer と Cron トリガー によるバックグラウンド処理を担当します。
Queue Consumer
Section titled “Queue Consumer”queue ハンドラ
Section titled “queue ハンドラ”Bell は2つのキューのコンシューマーとして機能します。
async queue(batch: MessageBatch<unknown>): Promise<void>キュー名に基づいて処理を分岐します。
push-notifications キュー
Section titled “push-notifications キュー”Web Push 通知を送信するキューです。
| 項目 | 設定 |
|---|---|
| バッチサイズ | 10 |
| タイムアウト | 1秒 |
| リトライ | 3回 |
| DLQ | push-notifications-dlq |
notification-queue キュー
Section titled “notification-queue キュー”マルチチャネル通知を分配するキューです。Fizz サービスが新着メッセージ時にこのキューに通知リクエストを投入します。
| 項目 | 設定 |
|---|---|
| バッチサイズ | 10 |
| タイムアウト | 1秒 |
| リトライ | 3回 |
| DLQ | なし |
通知ペイロード
Section titled “通知ペイロード”type NotificationPayload = { readonly type: string; // 通知種別 readonly recipientId: string; // 受信者 ID readonly recipientType: string; // 受信者種別 readonly shopId: string; // 店舗 ID readonly title: string; // タイトル readonly body: string; // 本文 readonly url?: string; // リンク先 readonly senderId?: string; // 送信者 ID};Cron トリガー
Section titled “Cron トリガー”scheduled ハンドラ
Section titled “scheduled ハンドラ”毎時実行されるスケジューラです。
async scheduled(_event: ScheduledEvent): Promise<void>| 項目 | 設定 |
|---|---|
| スケジュール | 0 * * * *(毎時0分) |
| 処理内容 | スケジュール済み PUSH メッセージのキューイング |
Email ハンドラ
Section titled “Email ハンドラ”Bell は Cloudflare Email Workers も処理します。
async email(message: ForwardableEmailMessage): Promise<void>受信メールを処理・転送するためのハンドラです。
エラーハンドリング
Section titled “エラーハンドリング”DLQ(Dead Letter Queue)
Section titled “DLQ(Dead Letter Queue)”| キュー | DLQ | 説明 |
|---|---|---|
| push-notifications | push-notifications-dlq | 3回リトライ後に DLQ に移動 |
| notification-queue | なし | 3回リトライ後に破棄 |
PUSH 送信エラー
Section titled “PUSH 送信エラー”| HTTP ステータス | 対応 |
|---|---|
| 201 | 送信成功 |
| 410 Gone | サブスクリプション削除(無効化) |
| 429 Too Many Requests | リトライ対象 |
| 5xx | リトライ対象 |