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:
18
src/index.ts
18
src/index.ts
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user