Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save philhawksworth/d5b4f7ea48541a20d183eba53b1400a7 to your computer and use it in GitHub Desktop.

Select an option

Save philhawksworth/d5b4f7ea48541a20d183eba53b1400a7 to your computer and use it in GitHub Desktop.

Revisions

  1. Phil Hawksworth created this gist Mar 2, 2023.
    19 changes: 19 additions & 0 deletions schedule-site-refresh-function.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // npm install @netlify/functions
    // to get access to scheduling function invocations
    // using cron notiation or some handy aliases

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

    const handler = async function(event, context) {

    // Trigger a site rebuild and deploy
    fetch("https://api.netlify.com/build_hooks/HOOK-ID-FROM-ADMIN", {
    method: "POST"
    });

    return {
    statusCode: 200,
    };
    };

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