Next.js Discord

Discord Forum

Calling a function at build time

Unanswered
Alaskan Malamute posted this in #help-forum
Open in Discord
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 💀

export const loadData = async () => {
    setTimeout(async () => {
        await loadData();
    }, 30);
    // saving current data in database & scheduling next update with setTimeout function


Thanks 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 🕵️
vercel has cronjobs so that would be the ideal place to do it: https://vercel.com/guides/how-to-setup-cron-jobs-on-vercel