Replies: 5 comments 5 replies
-
You need a separate server for persistent tasks. Consider NextJS as a "frontend server" which only exists for request/response cycle and template rendering, not a replacement for existing servers. |
Beta Was this translation helpful? Give feedback.
-
I would also say you need to decouple these two a bit. Even with Next.js API routes, you'll face some limitations. I am not sure if they function per sé should take 20 minutes to get followers but in general it is good practice that users only wait for synchronous processing on things they really need. For you function I'd use a message queue for things like that. You could pass the For example:
The user now sees a response and the function This only makes sense in case you don't need this data right away but if it takes 20 minutes anyway I don't think you want your user to wait for that. You could also split up your data into more messages to not reach the timeout. E.g. just 10 You need to define a separate consumer (either in Vercel or in another computing environment like AWS / Heroku). Your message queue could be something like RabbitMq, SQS, or similar. I've built https://serverlessq.com which is a hosted message queue solution that lets you decouple your applications exactly like I described above only with Vercel functions for example. It won't help you with the timeout but you could send a lot of messages and stay within your Vercel environment 🙁 I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
I have been using https://www.calen-ai.com/ - they are basically the vercel for long running tasks! super easy to setup |
Beta Was this translation helpful? Give feedback.
-
Would Vercel's new https://vercel.com/changelog/waituntil-is-now-available-for-vercel-functions |
Beta Was this translation helpful? Give feedback.
-
Long running tasks should be possible in Next with containerized self hosting |
Beta Was this translation helpful? Give feedback.
-
I have an app where after user signs in with 3rd party application, user's followings are retrieved from that service.
For each of the followings, I get more data from another API, and store this overall information in my database.
In my test account with 70 followings, this process takes ~20 minutes (includes timeouts due to API rate limits).
This works fine in development. But I have just deployed the app on Vercel, and when it comes to executing this function, firstly only a few followings are console-logged, then the function gets stuck: nothing is logged. Only when I refresh the page (which triggers
/api/auth/session
serverless function to get called), a few more are logged.I guess this is because Vercel 10s limit on execution for functions.
Please advice how I should handle this. Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions