Allow adding additional functions to `_worker.js`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating how the generated _worker.js is produced and review the proposed src/cloudflare-worker.js entry point. Check the closed pull requests linked to this issue for prior implementation context. Done means additional worker functions such as queue are available in the generated worker alongside HTTP handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100