Floky99
Floky99

Reputation: 732

Vercel NodeJS server goes to sleep with schedule job scheduled

I'm running a schedule job on button click from my frontend App sent to Nextjs (NodeJS) backend /api/ function which doesn't get triggered upon sending another request... Does anyone have an idea how could I persist NodeJS server to execute function at the given time without going to sleep and the need to send another request to it?

const job = schedule.scheduleJob(
                  buildingName,
                  endBuildTime,
                  function () {
                    console.log("Execute update!");
                  }
             )

Upvotes: 1

Views: 1428

Answers (1)

zouabi
zouabi

Reputation: 857

Serverless functions (Next.js API routes) have an execution timeout, which is 10 seconds on the hobby plan.

After 10 seconds, your function will be killed if it is still processing. Which is what is happening to your function. You are scheduling a job but that job will never execute because the function has been killed.

Upvotes: 4

Related Questions