Skip to content

Allow adding additional functions to _worker.js #10496

@smitssjors

Description

@smitssjors

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions