From 7d03c98b2343688277263e6604cb7f669386b6a0 Mon Sep 17 00:00:00 2001 From: MrBBot Date: Mon, 11 Sep 2023 17:38:08 +0100 Subject: [PATCH] Remove unused `handleQueue()` function from entry worker (#678) With #656, the Queues dispatcher is now implemented as part of the broker Durable Object. We no longer send message batches directly from Node.js, so can remove queue handling from the entry worker. Note the magic proxy enqueues messages through queue producer bindings like regular workers, so never used this endpoint directly. --- packages/miniflare/src/plugins/core/index.ts | 4 +--- .../miniflare/src/workers/core/constants.ts | 1 - .../src/workers/core/entry.worker.ts | 22 ------------------- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/packages/miniflare/src/plugins/core/index.ts b/packages/miniflare/src/plugins/core/index.ts index ee4173108a7b..4ee3dd620065 100644 --- a/packages/miniflare/src/plugins/core/index.ts +++ b/packages/miniflare/src/plugins/core/index.ts @@ -523,9 +523,7 @@ export function getGlobalServices({ durableObjectNamespace: { className: "ProxyServer" }, }, // Add `proxyBindings` here, they'll be added to the `ProxyServer` `env`. - // It would be nice if we didn't add all these bindings to the entry worker, - // but the entry worker shares lots of `devalue` code with the proxy, and - // we'd rather not duplicate that. + // TODO(someday): consider making the proxy server a separate worker ...proxyBindings, ]; if (sharedOptions.upstream !== undefined) { diff --git a/packages/miniflare/src/workers/core/constants.ts b/packages/miniflare/src/workers/core/constants.ts index 21785cca9d60..ccfb44a84cd7 100644 --- a/packages/miniflare/src/workers/core/constants.ts +++ b/packages/miniflare/src/workers/core/constants.ts @@ -3,7 +3,6 @@ export const CoreHeaders = { ORIGINAL_URL: "MF-Original-URL", ERROR_STACK: "MF-Experimental-Error-Stack", ROUTE_OVERRIDE: "MF-Route-Override", - CUSTOM_EVENT: "MF-Custom-Event", // API Proxy OP: "MF-Op", diff --git a/packages/miniflare/src/workers/core/entry.worker.ts b/packages/miniflare/src/workers/core/entry.worker.ts index 781fe408444b..b070bc952cb1 100644 --- a/packages/miniflare/src/workers/core/entry.worker.ts +++ b/packages/miniflare/src/workers/core/entry.worker.ts @@ -1,4 +1,3 @@ -import { unflatten } from "devalue"; import { Colorize, blue, @@ -11,7 +10,6 @@ import { } from "kleur/colors"; import { LogLevel, SharedHeaders } from "miniflare:shared"; import { CoreBindings, CoreHeaders } from "./constants"; -import { structuredSerializableRevivers } from "./devalue"; import { STATUS_CODES } from "./http"; import { WorkerRoute, matchRoutes } from "./routing"; @@ -188,21 +186,6 @@ function handleProxy(request: Request, env: Env) { return stub.fetch(request); } -async function handleQueue( - request: Request, - url: URL, - service: Fetcher, - startTime: number -) { - const queueName = decodeURIComponent(url.pathname.substring(1)); - const flattened = await request.json(); - const messages = unflatten(flattened, structuredSerializableRevivers); - const queueResponse = await service.queue(queueName, messages); - (queueResponse as FetcherQueueResult & { time: number }).time = - Date.now() - startTime; - return Response.json(queueResponse); -} - async function handleScheduled( params: URLSearchParams, service: Fetcher @@ -243,11 +226,6 @@ export default >{ } try { - const customEvent = request.headers.get(CoreHeaders.CUSTOM_EVENT); - if (customEvent === "queue") { - return await handleQueue(request, url, service, startTime); - } - if (url.pathname === "/cdn-cgi/mf/scheduled") { return await handleScheduled(url.searchParams, service); }