Open Barbapapazes opened 1 year ago
It is a good idea. I think we might support feature via a custom cloudflare:scheduledEvent
event triggered from default handler and can be hooked with nitro plugins to unblock feature 👍🏼
For general feature in nitro, for a while i had been thinking to introduce Tasks and Cron job features. This way we can universally support events/cronjobs and integrate it with each platform and also easily test them locally.
Describe the feature
Hello,
I would like to know how I could use Scheduled Event, developers.cloudflare.com/workers/runtime-apis/scheduled-event, directly from Nitro.
Additional information
- [ ] Would you be willing to help implement this feature?
AFAIK here's a workaround with custom nitro presets : https://nitro.unjs.io/deploy/custom-presets Add the scheduled function there and it should work
@Hebilicious I wouldn't advice that.
@pi0 Do you mind explaining what is wrong with a custom preset approach ? There's other cloudflare features that also need to be accessed that way, like queues for example https://developers.cloudflare.com/queues/get-started/#5-create-your-consumer-worker
It is a good idea. I think we might support feature via a custom cloudflare:scheduledEvent event triggered from default handler and can be hooked with nitro plugins to unblock feature 👍🏼
Not sure to fully understand. 🤔
Describe the feature
Hello, I would like to know how I could use Scheduled Event, developers.cloudflare.com/workers/runtime-apis/scheduled-event, directly from Nitro.
Additional information
- [ ] Would you be willing to help implement this feature?
AFAIK here's a workaround with custom nitro presets : nitro.unjs.io/deploy/custom-presets Add the scheduled function there and it should work
And how to support both a fetch
and a ScheduledEvent
? If I overwrite the entry
, the fetch
will not be generated.
@Hebilicious Nitro is a "Platform Agnostic" and "Zero Config" framework to build web servers. The whole topic of this issue is to make API available not to workaround and use a custom preset! Even introducing hooks is a workaround I am proposing until making the platform agnostic feature.
@Barbapapazes We need to register both fetch
and new scheduled
event handlers from main cloudflare entrypoints (just an example below)
addEventListener('scheduled', event => {
event.waitUntil(nitroApp.hooks.callHook('cloudflare:scheduled', event);
});
Describe the feature
Hello, I would like to know how I could use Scheduled Event, developers.cloudflare.com/workers/runtime-apis/scheduled-event, directly from Nitro.
Additional information
- [ ] Would you be willing to help implement this feature?
AFAIK here's a workaround with custom nitro presets : nitro.unjs.io/deploy/custom-presets Add the scheduled function there and it should work
And how to support both a
fetch
and aScheduledEvent
? If I overwrite theentry
, thefetch
will not be generated.
You should be able to place all Cloudflare specific exports (queue, scheduled, fetch) on the same worker.
@pi0 First class support would be great. There's definitely room for handling scheduled functions (or queues) agnosticly, perhaps we could even use an API close to the Cloudflare one ?
Recommending against using a custom preset means you can't use nitro to deploy a worker with these features.
That being said if you're happy with the hook solution, I can open a PR.
addEventListener('scheduled', event => { event.waitUntil(nitroApp.hooks.callHook('cloudflare:scheduled', event); });
@Hebilicious Nitro is a "Platform Agnostic" and "Zero Config" framework to build web servers. The whole topic of this issue is to make API available not to workaround and use a custom preset! Even introducing hooks is a workaround I am proposing until making the platform agnostic feature.
@Barbapapazes We need to register both
fetch
and newscheduled
event handlers from main cloudflare entrypoints (just an example below)addEventListener('scheduled', event => { event.waitUntil(nitroApp.hooks.callHook('cloudflare:scheduled', event); });
Okkk, I have something.
I didn't understand that it was possible to add this in the middle of a file. And it's possible because it's all event based. So many things to learn on Cloudflare.
I'd like to know exactly how this feature is going. There was a situation where I needed to access the queue handler and email handler of cloudflare workers.
Describe the feature
Hello,
I would like to know how I could use Scheduled Event, https://developers.cloudflare.com/workers/runtime-apis/scheduled-event, directly from Nitro.
Additional information