Add queue handler and tag-based queue dispatcher

- Add queue() handler in index.ts for WORK_QUEUE processing
- Add consumers/queue-dispatcher.ts with tag-based routing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-02-12 09:33:11 +09:00
parent 4b3cb21a15
commit 3d97190186
2 changed files with 63 additions and 0 deletions

View File

@@ -114,6 +114,24 @@ app.notFound((c) => c.text('Not Found', 404));
export default {
fetch: app.fetch,
async queue(batch: MessageBatch, env: Env): Promise<void> {
const { dispatchQueueMessage } = await import('./consumers/queue-dispatcher');
const queueLogger = createLogger('queue');
for (const msg of batch.messages) {
try {
await dispatchQueueMessage(msg.body, env);
msg.ack();
} catch (error) {
queueLogger.error('Queue message processing failed', error as Error, {
queue: batch.queue,
messageId: msg.id,
});
msg.retry();
}
}
},
async scheduled(event: ScheduledEvent, env: Env, _ctx: ExecutionContext): Promise<void> {
const cronSchedule = event.cron;
logger.info('Cron job started', { schedule: cronSchedule });