cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
342 stars 43 forks source link

Does Chanfana support Cloudflare queues and cron? #164

Closed shonubijerry closed 4 months ago

shonubijerry commented 4 months ago

I am trying to migrate from @cloudflare/itty-router-openapi v1.1.1

With chanfana v2.0.2 I noticed that the worker main entry file declared in wrangler.toml now uses the exported router module directly rather than the usual cloudflare module worker style where I can export fetch, scheduled, queue etc.

How do I add a cron schedule to a chanfana powered API?

I have tried changing the worker entry file to module worker file in wrangler.toml, and implement the chanfana router within the fetch scope. However, if I try to request an endpoint, the code breaks with below error.

[ERROR] A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.

And I get below as response. Error: The script will never generate a response. at async Object.fetch (file:///.../node_modules/miniflare/dist/src/workers/core/entry.worker.js:1023:22)

The logs does not show any meaningful message. Am I missing something?

Here is a repo that replicates the issue chanfana-api

G4brym commented 4 months ago

Hey @shonubijerry you can export crons and other properties like this

export default {
  fetch: app.fetch,
  scheduled: async (batch, env) => {},
}

I will add this piece to the docs Thanks for reporting

shonubijerry commented 4 months ago

@G4brym that did it. Thanks