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!
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.
Hey @voormedia and @niceshadowraze,
We’ve good news for both of you. Turns out that even though your codes are syntactically correct, it doesn’t satisfy our schedule matching logic which is why it was failing.
@voormedia, I believe you’ve already tried this, but the repo you shared didn’t have this solution, so I made the changes in the copy you provided and it appears to work fine.
The solution for both of you is to declare the schedule in your netlify.toml
like this:
[functions."function-name"]
schedule = "@hourly"
Hey @hrishikesh ,
I reverted to having the scheduling done in the .toml file and it works now!
Thank you very much for your support, guys. Really appreciated <3
Hi everyone… I was having this issue. Everything was configured correctly and it was on my “main” production branch. The “scheduled” badge showing up next to my functions but still nothing was working.
I decided to setup a new Netlify site & Github repo with only my functions and it worked!
The original project was an existing Next.js project. Scheduled functions just didn’t work in this environment.
This worked for me as well! Syntactically correct, but only when I moved the cron info into the toml file did it show up as scheduled!