-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nitro Tasks API #1974
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Tasks should probably be async, currently the |
If I use a nitro task in, let's say, Netlify will it leverage netlify background functions? |
I'm also interested on this. I would like to have for example my normal code on vercel-edge but run tasks on vercel lambda (5min timeout vs 25 seconds) |
How to disable it, because i use dir tasks for other stuff? |
It is planned to support running these tasks from cli without running the server? |
Nitro already has a CLI preset too! However it is tricky to tell now when we can do support it this way now. |
Any plan for support seconds scheduling? |
@robin-dongbin You mean this https://nitro.unjs.io/guide/tasks#scheduled-tasks or something different? (like a pattern for <1 minute schedule?) |
Yes, that's what I want. Is it possible? I know that cron do not support that, but Laravel has support this last year. |
@pi0 ... I have just tested the experimental scheduled task feature. It works really well! Thanks! Just one question: would it be possible to have a config setting to execute a scheduled task immediately after the cron is scheduled? Example: a task running every 10 minutes: executes once the server starts, and then every 10 minutes after that? I saw in the |
@go4cas Maybe use a Nitro plugin to triger them on startup? (also @robin-dongbin I also wonder if you need to trigger something this frequently, maybe a |
But won’t there be conflicts if a node in a cluster with 8 processes and all 8 processes will cause a task, but this behavior should not happen? It turns out you need to find someone who has a free worker and give him a task from the master? |
For time being, scheduled tasks are not supported in cluster mode the exactly meet this requirement (share a safe lock among them) and it is doable. Regardless inside your interval you can call |
I apologize if this isn't the correct forum. But how is supposed to run those tasks in Nuxt project from CLI? Nuxt CLI will be implemented to invoke those tasks from the URL or we should run directly from nitro cli? |
Yes. |
With async tasks, and enforcing task payloads to be serializable early on it will be possible in the future to dispatch tasks to queues. Shamelessly taking the concept from Laravel: https://laravel.com/docs/10.x/queues The nice thing about that way of working is that when queues are configurable (e.g. redis, some AWS service, etc.) then the dispatch mechanic becomes really usefull for dispatching work to different parts of your architecture. |
|
@pi0 Is there another way to use Netlify background functions with Nitro to handle multiple instances of a background function? |
Using Nuxt 3. Tried building an endpoint to get scheduled jobs using 'scheduledJobs' variable imported from "cron" package directly, see here: https://croner.56k.guru/usage/examples/#naming-jobs The 'scheduledJobs' variable however returns an empty array always. Is there a way to do this? To monitor scheduled and running jobs? |
Hi @pi0, I'm wondering how scheduled tasks are handled in a serverless context? For example, I am currently using the Firebase preset which uses a Firebase Function as the 'server'. Since the server is not long-lived, would scheduled tasks execute each time the service is called, or are they not included in unsupported presets? |
hey, is it currently possible to create a nuxt application with tasks and get it to work with cloudflare triggers? (as it's deployed as a pages application I couldn't get it to work) update: i got it to work after deploying the nuxt app with the cloudflare_module preset here which deploys it as a workers application |
Hello, I was trying to run Btw, Thank you for a great API! |
@carlos-duran i had the same issue i have an open pull request at the moment that should fix it btw you can edit your buildDir in the nuxt config // https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-04-03',
devtools: { enabled: true },
buildDir: '.nitro',
nitro: {
buildDir: '.nitro',
experimental: {
tasks: true,
}
}
}) and replace .nuxt in the tsconfig file with .nitro |
Can you please give an example how you did it? |
@aligzl hey, I pretty much exactly followed the docs for the cloudflare_preset module which I believe builds/deploys the app as a workers application and not as a pages application. Nitro tasks started working for me after that |
hmm, i am using nuxt hub, i guess i will mess it up if i touch it :) |
I'm in the same boat with NuxtHub. With the new Cloudflare worker updates, support for this will be coming soon to NuxtHub I believe (cc @atinux 👀) |
The |
Love to see this can't wait until it's fully ready |
I tried this 3 weeks ago and now I can't make them work anymore for some reason following the same guide I had specified here: solidjs/solid-docs#964 I also tried in Tanstack Start which is also based on Nitro and it also doesn't work there. Did something change somehow in the last 3 weeks 😕? Seems like the last release was more than 3 weeks ago so I'm assuming no. Anybody else has the same problem? Or if you made it work could you post your |
@shoooe both tanstack-start and solid are based on a wrapper "Vinxi" which sadly abstracts away full features of Nitro (consider even dev server of nitro is not used when using vinxi!). Currently Nuxt, AnalogJS or pure Nitro projects can use all features. Hopefully this changes in the near future for them. |
Im using Nitro Tasks on Nuxt3, and i have an issue when i deploy them on Vercel. Everything works great locally, but when i deploy app on vercel the Task mysteriously dies and i do not have any information why. When i've added console.logs to the function i see that at some point they stops. Any idea how to debug it, or why it might happened? |
I would imagine it's timing out. Vercel is not really the best place for long-lived tasks. |
I have this in my nuxt.config ...
vercel: {
functions: {
maxDuration: 120,
},
}, Task should take about 30-45sec. It looks like handling async calls to external api, crashes the task. Is there any recomended place to deploy Nuxt3 with working tasks? |
Added vercel support to tracker 🤞🏼 In the meantime, you can instruct nitro config and create a custom handler for vercel: export default defineNitroConfig({
vercel: {
config: {
crons: [
{
// TODO: create server/api/_cron.ts event handler
path: "/api/_cron",
schedule: "0 0 * * *",
}
],
},
},
}); |
For me it is issue with single Nitro Task, run by built-in runTask function not scheduled crons. Sometimes it works after even 10-15minutes, but locally task runs in about 15sec. I found out openAi returns me error: |
thanks pi0. Also seeing support for this way of defining the cronjob in the nuxt.config file.
|
@pi0 I have a question. I use Nitro development server and deploy it with docker. There may be multiple pods. Do we have any way to ensure that the task will only run once? For example, Redis shared lock, etc. |
@pi0 hi, thanks for the hard work on this feature. I really need that for a data scrawling scenario. Is there any workarounds about long-running tasks on production environments like netlify right now?
|
I'm curious if there's any plan for a queue system like Rails Solid Queue or Laravel Queues. (I saw the previous comments about Laravel Queues) Things like these would be great:
|
hi @pi0, does If the task is scheduled to be every min, something like that? :
|
Nitro tasks allow on-off operations in runtime.
Docs: https://nitro.unjs.io/guide/tasks
The text was updated successfully, but these errors were encountered: