Scheduled function shows as deployed but never runs and there are no logs

Yeah, I’ve done both. However, I’m not the team/site owner, do you think it might have something to do?

I used the basic function from the Scheduled Functions documentation as a test, setting it to run every 5 minutes. This has worked for me, logging the event.

On the functions page, it shows the next scheduled run time.

After the second running (at 8am) when I checked the logs (at ~8:01am) nothing was shown when “latest” was selected, I needed to change to “last hour”. So it is possibly something with the view you are using @niceshadowraze ?

(Curiously @hillary at 8:07am I would have expected to see the logs for the 8:05am running of the function under “latest” yet nothing is shown, I have to switch to “last hour” to see the log from 2 minutes ago. Small bug perhaps?)

“Latest” shows no logs for me on all functions. Changing it to “last hour” shows “No results found for query” even for the simple function I posted above. My understanding is that console.log, console.warning, etc should end up here if the function executed? I don’t think they are executing at all if that’s the case

I’ll create a test site I own with some test functions

So I created a test site and can confirm I see the logs for this function https://github.com/gaspardip/remix-scheduled-functions/blob/master/netlify/functions/foo/index.ts

I wonder if me not being the owner of the other site might have something to do with functions not executing? maybe the owner has to enable scheduled functions through labs too? I honestly have no other explanation.

Ok I think I found the issue, functions published to any branch that is not the production branch are not being run, check these functions https://github.com/gaspardip/remix-scheduled-functions/tree/develop/netlify/functions, and their logs

1 Like

As per below, they only run on the main/production branch (at this point; when they are out of labs this may change.)

Well that wasn’t mentioned in the docs anywhere, would be useful to have it there imo. It’s quite unfortunate because we are using branch subdomains and our default branch doesn’t have the same content as develop (they are even different builds, default branch is the landing, develop is the development branch for our app). I guess the workaround for now is to include the relevant code in the default branch.

howdy @niceshadowraze - sorry about the frustration for this! we’re gonna look into the behaviour you are describing and see if we can at very least make the docs more clear so others don’t have to go through the same journey to figure this out. It takes a village. thanks again!

1 Like

That would be great, thanks!

Hi, thanks a lot for the scheduling feature – that was exactly what we needed <3

Only problem, though: we’re having the same issue (function is deployed, works as expected when manually launched, but doesn’t run when expected and no logs to boot), although it has been deployed to the production branch.

Moreover, on the functions page the “Scheduled” tag & next execution time don’t show up:

Would we be missing something important in the setup?

(tried both ways of setting up the scheduler – in the function itself and in netlify.toml – with the same results)

Hey @voormedia

Just as a double-check on the functions page does the button say “Disable Scheduled Functions” or “Enable Scheduled Functions”?

Hi, @coelmay! Thank you for your reply.

It says “Disable Scheduled Functions”, just like in your screenshot:

Great. But you don’t see a “Scheduled” next to the function?

You say you’ve tried both configuration methods outlined in the docs here and here? The function from my screenshot is exactly the code from the first link (and is working) and have deployed using the second method today without issue too.

Are you able to share the repository, or code?

Correct. Unlike your screenshot, no “Scheduled” for me next to the function.

And I did try both configurations you linked, the inline and the .toml methods.

The code for both attempts:

1. Inline

netlify/functions/rebuild/rebuild.js:

const {schedule} = require("@netlify/functions");
const fetch = require("node-fetch");

const REBUILD_URL =
  "https://api.netlify.com/build_hooks/XXXX";

const handler = async function(event, context) {
  await fetch(REBUILD_URL, {method: "POST"});

  return {
    statusCode: 200,
  };
};

module.exports.handler = schedule("@hourly", handler);

2. .toml

netlify/functions/rebuild/rebuild.js:

const fetch = require("node-fetch");

const REBUILD_URL =
  "https://api.netlify.com/build_hooks/XXX";

const handler = async function(event, context) {
  await fetch(REBUILD_URL, {method: "POST"});

  return {
    statusCode: 200,
  };
};

module.exports.handler = handler;

and netlify.toml:

...
[context.production.environment]
  TZ = "Europe/Amsterdam"

[functions."rebuild"]
  schedule = "@hourly"

Hey @voormedia,

I don’t see anything wrong with the syntax, or anything else that stands out. Would you be able to share the repo so we can test this? Seems like there could be something weird happening with a specific use case.

Hey @hrishikesh,

Thank you for your reply & help. I’ll send you a copy of the repo to your personal inbox, to limit exposure of it. Hope its enough!

Hi @voormedia

I can see the function being processed but not handled as a scheduled function. Can you please do the following:

  • change the content of the function so we build it again (one of the triggers is having different content)
  • publish that deploy and let us know so we can take a closer look at this

That will allow us to check a more recent version of the function.

I’m having a similar issue as above. Notably, my function is written in TypeScript, but follows basically the same code as the scheduled functions guide. Is it required that I use the CommonJS require(...) / module.exports.handler syntax, as listed in the docs? I’d really hope not, so that I can use TS like the rest of my project, and as I have with non-scheduled functions in the past.

Here’s a version without the API calls:

import { Handler, schedule } from "@netlify/functions";

// Mon-Fri, a bit before :30 and :00 from 12am through 1am and 11am through 11pm UTC
// (4:26+4:56am - 6:26+6:56pm PT)
const SCHEDULE = `26,56  0-2,12-23 * * 1-5`;

const handler: Handler = schedule(SCHEDULE, async () => {
  if (process.env.NETLIFY_BUILD_HOOK_URL) {
    // fetches data, calls build hook if applicable, console.logs, returns 200,
  } else {
    // needs configuration, console.log
  }
});

export { handler };

It’s been deployed and published, but similarly shows up without the “Scheduled” marker, and still lists an endpoint, even though the docs make it seem like it wouldn’t.

Scheduled functions enabled:

Hi, @gualter . Thank you for your help!

I’ve slightly changed the function and redeployed it. We cross our fingers that you’ll be able to figure out what’s wrong.

Hey there folks, thanks so much for your patience here. Our support team is still looking into this and will follow up in this thread when we have more information.