Running tasks or server-code at all times
Answered
Masai Lion posted this in #help-forum
Masai LionOP
Hello! Within my application, I'm using a small-time API that provides some data to me. I would like to implement a history of that data, but this is not included on the endpoint. So my only option is to set up a task which fetches the data, prepares the history and saves it for any user when they load the page.
I do not just want to save the history when there is someone browsing the website, I also need it to do this when nobody is there. How exactly would I implement an interval like this? On the page router documentation I've read that you can add your own index file but there is no such thing when using the app router.
I'd appreciate any advice or tips!
I do not just want to save the history when there is someone browsing the website, I also need it to do this when nobody is there. How exactly would I implement an interval like this? On the page router documentation I've read that you can add your own index file but there is no such thing when using the app router.
I'd appreciate any advice or tips!
Answered by European sprat
Run a cron service where it executes a curl request to your endpoint
5 Replies
European sprat
Create an endpoint which uses revalidatePath or revalidateTag and uses a secret header or query param then hit that endpoint on whatever interval you want using some other service which can do that for you. I think I've seen people mention GitHub actions but there are infinite number of possible "cron" type solutions out there
@European sprat Create an endpoint which uses revalidatePath or revalidateTag and uses a secret header or query param then hit that endpoint on whatever interval you want using some other service which can do that for you. I think I've seen people mention GitHub actions but there are infinite number of possible "cron" type solutions out there
Masai LionOP
Do you have any recommendation for the other service part, because I prefer to keep everything within NextJS but if that is not possible I can always make an ASP.NET backend that it fetches the "up to date" history from.
European sprat
Run a cron service where it executes a curl request to your endpoint
Answer
European sprat
Vercel might even have a cron type service too. Look at GitHub actions as well
Masai LionOP
Ah, thanks. I'll do that, great idea!