-
Notifications
You must be signed in to change notification settings - Fork 431
Closed as not planned
Labels
type: bugcode to address defects in shipped codecode to address defects in shipped code
Description
Describe the bug
I'm attempting to run a scheduled function using Netlify's Scheduled Next JS API Routes. While it appears that Netlify is calling the function on schedule, the code inside of it is not being ran.
I added a typescript file in the pages/api that runs a build hook every hour:
import fetch from "node-fetch";
const BUILD_HOOK = "*****";
export default async (req: NextApiRequest, res: NextApiResponse) => {
console.log("ATTEMPTING DAILY REBUILD");
try {
const url = `${BUILD_HOOK}?trigger_title=daily_build&clear_cache=true`;
await fetch(url, { method: "POST" });
console.log("DAILY REBUILD SUCCEEDED");
res.status(200).send({});
} catch (err) {
console.log("DAILY REBUILD ERROR:", err);
res.status(500).send({});
}
};
export const config = {
type: "experimental-scheduled",
schedule: "0 * * * *",
};
After deploying, Netlify properly identifies it as a scheduled function and tries to run it once an hour:

The problem is that nothing happens. It looks like Netlify is calling the build function in the logs above, but it seems like the script isn't running.
When I manually trigger the API route locally, the code properly executes.
Steps to reproduce
- Create a scheduled Next JS API route according to this article
- Push to production
- Verify that the code inside the function does not run
Configuration
No response
Environment
System:
OS: macOS 11.5.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 963.72 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
npmGlobalPackages:
netlify-cli: 12.7.2
conor and Ezall2001RohitRajendran
Metadata
Metadata
Assignees
Labels
type: bugcode to address defects in shipped codecode to address defects in shipped code