Scheduled function doesn't invoke

Hey,
yesterday I deploy test scheduled function, but unfortunately there is no evidence the function to be invoked. As you can see on a screenshot everything looks correctly setuped and if I invoked it locally it works as expected. Do you have any suggestions?

P.S. I tested different function syntax, inline, toml schedules, etc

function:

import { Handler } from '@netlify/functions'

export const handler: Handler = async () => {
  console.log('Processing complete')
  return {
    statusCode: 200,
  }
}

netlify.toml

[functions."test"]
schedule = "*/2 * * * *"

Hi @melbon,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Could you provide us with the site name (for example sitename.netlify.app) so we can investigate further?

You’ll want to ensure you’re not running against any of the limitations mentioned here:

Hi @Melvin

I’m also facing the same issue, but can’t figure out why my scheduled function isn’t invoked :frowning:
I tried with a simple scheduled function based on these docs: Scheduled Functions | Netlify Docs

Also this test-scheduled-function seems to get deployed but ultimately not invoked on the published site. My project is setup with turborepo and has two main apps: app & web.
Build settings for app (scheduled function is used only in app):
Base directoy: /
Package directory: apps/app
Build command: turbo run build --filter app
Publish directory: apps/app/.next
Functions directory: netlify/functions

netlify site name: appsummercamp-nak

Thank you for your help

Hi @owieth,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Have you been able to get the schedule function working locally? We have docs that can help with testing here:

Could you give that a try and let us know if the scheduled function works locally?

Additionally, I noticed while investigating the site, that a Netlify DNS Zone has been configured but that it is not active.

We have a Support Guide on how to detect and fix inactive DNS Zones:

I mention this cause it could be the cause of the issue with the scheduled function not working.

@Melvin thanks for replying!

I updated my DNS settings and now it seems that it correctly resolves the netlify name servers :slight_smile:

Locally I’m able to run the functions:

Structure of my app and build settings on netlify:

Do you see something wrong in my configuration?

Hi @owieth,

Thanks for following up.

We were able to check within our internal logs, that the scheduled functions are running for your site. Both the schedule functions named scheduled-function and test-scheduled-function.

If you’re looking in the function logs, the scheduled functions will only show if you’ve added console.log() (or other logging) to the scheduled functions.

I made a test site using:

exports.handler = async () => {
    console.log("Scheduled Function is running at", new Date().toISOString());
    
    return {
      statusCode: 200,
      body: "Scheduled Function executed successfully!",
    };
  };

netlify.toml


[functions]
directory = "netlify/functions"

[functions.scheduled-function-test]
  schedule = "*/5 * * * *"

And I was able to get it to display on the function log with the console.log():

Hi @Melvin,

Thanks for testing, unfortunately it still seems not working for me :frowning:

I tried with two different functions for my test-scheduled-function:

exports.handler = async () => {
  console.log("Scheduled Function is running at", new Date().toISOString());

  return {
    statusCode: 200,
    body: "Scheduled Function executed successfully!",
  };
};

and also the typescript example:

export default async (req: Request) => {
  const { next_run } = await req.json();

  console.log("Received event! Next invocation at:", next_run);
};

neither of them logs something into my functions logs, for last hour, last 2 hours and last day I get this:

No results found for query

In my functions metrics, I can see that my scheduled functions are not invoked at all:

so it seems that they don’t get invoked somehow, hopefully this helps :slight_smile:

Thanks!

Hi @owieth,

Looks like the schedule hasn’t been set:

I’m not seeing the schedule o the time for the next execution, like in this example:

You’ll want to check your netlify.toml and ensure that the schedule is covering test-scheduled-function. Similar to:

[functions]
directory = "netlify/functions"

[functions.scheduled-function-test]
  schedule = "*/5 * * * *"

Hi @Melvin
yeah sorry that got lost while testing the last updates but was there before…

now the function has a schedule to run every 5 minutes but still no invocations visible:

Hi @owieth,

Thanks for following up. Would you be able to share a minimum reproduction? As I’m unable to replicate an issue, the scheduled function I shared is working and I do see the console.logs in the function logs as well that the functions are being invoked on the function metrics page. So I’m at a lost why it’s not working for you. If you could share a minimum reproduction or make your github repo public that’ll give us a chance to review.

Hi @Melvin

I setup a new repo to reproduce the missing logs but now I can see it in the functions:

so it seems that my other repository, something is causing the functions not to be triggered, need to debug this further why that’s the case. Can you check if my DNS for the site appsummercamp-nak is correctly setup and has no inactive DNS zones? Thanks :slight_smile:

Hi @owieth,

Yep, looks like the DNS is setup correctly. I’m showing that you’re using the Netlify name servers:

dig summercamp-nak.ch NS +trace | tail -n 6
summercamp-nak.ch.	3600	IN	NS	dns1.p09.nsone.net.
summercamp-nak.ch.	3600	IN	NS	dns2.p09.nsone.net.
summercamp-nak.ch.	3600	IN	NS	dns3.p09.nsone.net.
summercamp-nak.ch.	3600	IN	NS	dns4.p09.nsone.net.
;; Received 135 bytes from 198.51.44.73#53(dns3.p09.nsone.net) in 31 ms

Our Support Guide for inactive DNS zones here:

helps explain the steps you can follow to see if the zone is inactive and how to fix it.

1 Like