From eb40a8f43530936f50181fbcd02463b66588188d Mon Sep 17 00:00:00 2001 From: Andrew Bierman <94939237+andrew-bierman@users.noreply.github.com> Date: Sun, 21 Jul 2024 22:16:40 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20bucket=20on=20queue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/index.ts | 27 +++++++++++++++++++-------- server/src/queue/index.ts | 2 +- server/wrangler.toml.example | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index 65584dea0..27832296f 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,16 +1,17 @@ +import { type Ai } from '@cloudflare/ai'; import { Hono } from 'hono'; -import { fetchHandler } from 'trpc-playground/handlers/fetch'; -import { appRouter } from './routes/trpcRouter'; -import { honoTRPCServer } from './trpc/server'; import { cors } from 'hono/cors'; -import { securityHeaders } from './middleware/securityHeaders'; +import { fetchHandler } from 'trpc-playground/handlers/fetch'; +import { CORS_METHODS } from './config'; import { enforceHttps } from './middleware/enforceHttps'; +import { securityHeaders } from './middleware/securityHeaders'; +import { queue } from './queue'; import router from './routes'; -import { CORS_METHODS } from './config'; -import { type Ai } from '@cloudflare/ai'; +import { appRouter } from './routes/trpcRouter'; import { httpDBContext } from './trpc/httpDBContext'; +import { honoTRPCServer } from './trpc/server'; -interface Bindings { +export interface Bindings { [key: string]: any; DB: IDBDatabase; VECTOR_INDEX: VectorizeIndex; @@ -21,6 +22,8 @@ interface Bindings { MAPBOX_ACCESS_TOKEN: string; CLOUDFLARE_ACCOUNT_ID: string; VECTORIZE_API_KEY: string; + readonly ETL_QUEUE: Queue; + readonly ETL_BUCKET: R2Bucket; } const TRPC_API_ENDPOINT = '/api/trpc'; @@ -74,4 +77,12 @@ app.use(TRPC_PLAYGROUND_ENDPOINT, async (c, next) => { app.use(`${HTTP_ENDPOINT}/*`, httpDBContext); app.route(`${HTTP_ENDPOINT}/`, router); -export default app; +// SETUP CLOUDFLARE WORKER WITH EVENT HANDLERS +const worker = { + ...app, + fetch: app.fetch, + queue, +}; + +// EXPORT WORKER +export default worker; diff --git a/server/src/queue/index.ts b/server/src/queue/index.ts index 6e8944722..82e7a081a 100644 --- a/server/src/queue/index.ts +++ b/server/src/queue/index.ts @@ -23,7 +23,7 @@ const queueHandlersMap = new Map< string, (batch: MessageBatch, env: Bindings) => Promise >([ - ['etl-queue', handleEtlQueue], + ['packrat-etl-queue', handleEtlQueue], // Add more handlers here ]); diff --git a/server/wrangler.toml.example b/server/wrangler.toml.example index 04f3e0231..fa69345d6 100644 --- a/server/wrangler.toml.example +++ b/server/wrangler.toml.example @@ -28,7 +28,7 @@ max_batch_size = 10 max_batch_timeout = 5 [[r2_buckets]] -bucket_name = "etl-bucket" +bucket_name = "packrat-etl-bucket" binding = "ETL_BUCKET" # Add vars below