Calling a function at build time
Unanswered
Alaskan Malamute posted this in #help-forum
Alaskan MalamuteOP
Hey fellas! How can I run function once at build time? I have a simple web scrapper which runs itself every 30 minutes, but how can I initiate that? Don't wanna create multiple instances of recursion 💀
Thanks in advance!
export const loadData = async () => {
setTimeout(async () => {
await loadData();
}, 30);
// saving current data in database & scheduling next update with setTimeout functionThanks in advance!
3 Replies
Alaskan MalamuteOP
Perhaps there's an alternative built-in approach for that, which I'm not aware of. Let me know if you know some magic tricks 🕵ï¸
@Alaskan Malamute Hey fellas! How can I run function once at build time? I have a simple web scrapper which runs itself every 30 minutes, but how can I initiate that? Don't wanna create multiple instances of recursion 💀
ts
export const loadData = async () => {
setTimeout(async () => {
await loadData();
}, 30);
// saving current data in database & scheduling next update with setTimeout function
Thanks in advance!
Maybe just separate it to a different nodejs script and run it alongside the nextjs server (not applicable for vercel, but what you try to do above can’t work for vercel either, if you host on vercel you likely have to use a proper cron job service)
vercel has cronjobs so that would be the ideal place to do it: https://vercel.com/guides/how-to-setup-cron-jobs-on-vercel