Closed nikolasdas closed 8 months ago
Now you can use asynchronous callbacks.
import { defineCronHandler } from '#nuxt/cron'
export default defineCronHandler('everyMinute', async () => {
const data = await $fetch<{ repos: any[] }>('https://ungh.cc/orgs/unjs/repos')
console.log(`UnJS has ${data.repos.length} repositories available`)
}, { runOnInit: true })
// stdOut: UnJS has 88 repositories available
If it doesn't make sense to you, write a case study.
Sorry I should have clarified this a bit more, passing a async callback seems to work fine, yes. But the type definition requires a sync function, would it be possible to change this?
Can you give me an example, I guess I don't understand what you're talking about.
https://github.com/hywax/nuxt-cron/blob/b69fcc23e05fcf5146666a6cc5c3f9cc5ffe056f/src/runtime/types.d.ts#L24
Because of this type definition I get a @typescript-eslint/no-misused-promises
warning. I know this might be nitpicky, but I try to have my eslint rules strict and avoid eslint-disable comments 🙈
I can create a PR if you'd like, but wanted to make sure it is okay to use an async function in the first place
Looked at the types, I can replace CronTick
export type CronTick = () => void | Promise<void>
Am I correct in assuming that's what you're looking for?
Yes, this would make my linter and subsequently me happier 👍
Thank you for your awesome support! And this cool nuxt module of course :)
Any plans for
defineCronHandler
to accept an asyncCronTick
callback? Would be very helpful! :)