import type { ExecutionContext, D1Database, DurableObjectNamespace, } from '@cloudflare/workers-types' import { CacheCreator } from './src/jobs/cache-creator' import { createApp } from './src/app' import { ensureWorkerInit } from './src/lib/worker-init' import { handleNotifQueue, handleOrderPlacedQueue, handleOrderCancelledQueue, } from './src/lib/queue-consumer' export { CacheCreator } export default { async fetch( request: Request, env: Record & { DB?: D1Database CACHE_CREATOR: DurableObjectNamespace NOTIF_QUEUE: { send: (message: unknown) => Promise } ORDER_PLACED_QUEUE: { send: (message: unknown) => Promise } ORDER_CANCELLED_QUEUE: { send: (message: unknown) => Promise } }, ctx: ExecutionContext ) { console.log(env) ensureWorkerInit(env) const app = createApp() return app.fetch(request, env, ctx) }, async queue( batch: any, env: Record & { NOTIF_QUEUE: { send: (message: unknown) => Promise } ORDER_PLACED_QUEUE: { send: (message: unknown) => Promise } ORDER_CANCELLED_QUEUE: { send: (message: unknown) => Promise } DB?: D1Database NOTIF_QUEUE_NAME: string ORDER_PLACED_QUEUE_NAME: string ORDER_CANCELLED_QUEUE_NAME: string } ) { ensureWorkerInit(env) console.log('from the queue handler') if (batch?.queue === env.NOTIF_QUEUE_NAME) { handleNotifQueue(batch) return } if (batch?.queue === env.ORDER_PLACED_QUEUE_NAME) { await handleOrderPlacedQueue(batch) return } if (batch?.queue === env.ORDER_CANCELLED_QUEUE_NAME) { await handleOrderCancelledQueue(batch) return } handleNotifQueue(batch) }, }