Scheduled Function trigger does not show in Deploy log

I have deployed the recently introduced Scheduled Functions feature available from netlify labs for a site (20q.netlify.app). I wish to have netlify execute the npm run generate script (its a Nuxt project) every day once.

The functions tab even shows the function as below:

test-scheduled-functionScheduled

Created on Jun 21 (19 hours ago)

Next execution on Jun 23 at 5:30 AM

The function itself is a standard daily function

const { schedule } = require('@netlify/functions')

const handler = async function(event, context) {
  console.log("Received event:", event)
  return {
    statusCode: 200,
  };
};

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

Even though the functions scheduler shows a date and time, I find that the deployment logs do not show a fresh deployment at the appointed time.

Is my understanding of scheduled functions wrong or is there something else that needs to be done to run the deployment function on a daily basis

Thanks

Hey @rrrepos

When you look at the log for a function, by default it shows “Real-time” logs. However, that doesn’t necessarily mean “right now” I have found. Changing the timeframe may show the log for the function.

The function deployed here is the same as yours (as found in the documentation) except the timing was modified to make it run every 15 minutes (shorter timeframes are handy when testing like this otherwise you only get one chance to test per day.)

const { schedule } = require('@netlify/functions')

const handler = async function(event, context) {
    console.log("Received event:", event)

    return {
        statusCode: 200,
    };
};

module.exports.handler = schedule("*/15 * * * *", handler);

The log above is the output from the first running of the scheduled function.

Thanks @coelmay .

I am unable to locate the menu to display scheduled functions log (embarrassed that I cannot find). Can you help me with that?

And in your case, running this does re-deploy the site. right?

Thanks

In the Netlify UI, select the site the function is a part of. The navigation at the top of page should look like this

Select Functions and you will see a list of functions deployed to the site. You will then see a list of functions. If you have a scheduled function, it will show Scheduled beside the name. If you don’t see this, either the function hasn’t deployed, or you haven’t enabled scheduled functions for that site.

Yes @coelmay I now see the menu and the log that showed it was run earlier. Thanks.

Since my intention was to re-run the deploy which in turn should call npm run distribute which I have set. Would this schedule cause that to script to run?

Thanks

You cannot run a command such as npm run distribute from within a function, scheduled or otherwise. In order to trigger a new build, you would need to call a build hook using fetch from within the function.

Okay. got it. I read through the documentation. Will give it a try. Thanks @coelmay