-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Allow adding additional functions to _worker.js #10496
Copy link
Copy link
Open
Labels
Description
Describe the problem
Cloudflare Queues is currently in open beta. It would be nice to be able to consume messages from the same worker that handles HTTP requests, as opposed to having to creating a separate worker. For a worker to consume from a queue a new queue function needs to be defined on the worker object.
// worker.js
export default {
async fetch(request, env, ctx) {
// Handle request...
},
async queue(batch, env) {
// Process batch...
},
};Currently there is no easy way to add this queue function to the woker object in the generated _worker.js.
Other Cloudflare services such as Email Workers follow a similar approach.
Describe the proposed solution
I'd suggest a special src/cloudflare-worker.js file which would export functions such as queue which then during compilation get added to the _worker.js file.
// src/cloudflare-worker.js
export const queue = (batch, env) => // Process batch...Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
Reactions are currently unavailable