Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next JS API route Schedule Function doesn't run in Production #5603

Closed
ui-jb opened this issue Mar 31, 2023 · 1 comment
Closed

Next JS API route Schedule Function doesn't run in Production #5603

ui-jb opened this issue Mar 31, 2023 · 1 comment
Labels
type: bug code to address defects in shipped code

Comments

@ui-jb
Copy link

ui-jb commented Mar 31, 2023

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:
image

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

  1. Create a scheduled Next JS API route according to this article
  2. Push to production
  3. 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
@serhalp
Copy link
Contributor

serhalp commented Jul 16, 2024

Marking this as stale as it is over a year old. Please feel free to reopen if you are still having issues.

(FYI, this doesn't seem like it's an issue with netlify-cli. Consider asking for help at https://answers.netlify.com instead.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants