Netlify Scheduled Functions: Set Up Serverless Cron Jobs

Netlify Scheduled Functions: Set Up Serverless Cron Jobs

Perttu Lähteenlahti
Updated March 11, 20264 min read
scheduled-functionscron-jobsserverlesstypescript
Share:

Most projects eventually need some kind of background task. Maybe you want to rebuild your site daily, sync data from an external API, or clean up old records. On a traditional server, you'd set up a cron job and forget about it. But if you're on Netlify, you probably don't want to manage a server just for a scheduled task.

That's where Netlify Scheduled Functions come in. They're regular Netlify Functions that run on a schedule — basically cron jobs, but serverless.

How they work

A scheduled function is just a Netlify Function with a schedule attached. You write the function, tell Netlify when to run it, and deploy. That's it — no infrastructure to manage, no servers to keep running.

They run in the background, don't need any user interaction, and support anything from @hourly to custom cron expressions.

Step 1: Write the function

Create a file at netlify/functions/test.ts:

import { Handler } from "@netlify/functions"

export const handler: Handler = async () => {
  console.log("Scheduled function ran")

  return {
    statusCode: 200
  }
}

Nothing special yet — this is just a regular function. The schedule part comes next.

Step 2: Add a schedule

You've got two options here.

Option A: netlify.toml

Add this to your netlify.toml:

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

Deploy, and Netlify starts running it every hour.

Option B: Inline in the function

If you'd rather keep everything in one file:

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

const task: Handler = async () => {
  console.log("Running scheduled task")

  return {
    statusCode: 200
  }
}

export const handler = schedule("@hourly", task)

Both approaches work the same way. I prefer netlify.toml because I can see all my schedules in one place, but the inline approach is nice if you want the function to be self-documenting.

Schedule syntax

The built-in shortcuts:

  • @hourly — every hour at minute zero
  • @daily — midnight
  • @weekly — Sunday at midnight
  • @monthly — first of the month
  • @yearly — January 1st

For anything more specific, use a cron expression:

5 4 * * *

That runs every day at 4:05 AM. If cron syntax makes your eyes glaze over, crontab.guru is your friend.

Testing without waiting

You don't have to sit around waiting for the schedule to fire. The Netlify CLI lets you invoke the function manually:

netlify functions:invoke test

This runs it immediately, which is way better than deploying and then waiting an hour to see if it works.

What I've used these for

Some real patterns I've found useful:

  • Triggering daily redeploys — call a Netlify deploy hook from the function, so your static site rebuilds on a schedule. Great for blogs that publish posts with future dates.
  • Syncing data from external APIs — pull data from a CMS or third-party service and cache it.
  • Sending periodic pings — uptime monitoring, status checks, heartbeat signals.
  • Cleaning up old data — delete expired records, rotate logs, that sort of thing.

The deploy hook pattern is probably the most common one. You create a build hook in Netlify, then write a scheduled function that POSTs to it. Your site rebuilds automatically at whatever interval you set.

Limits to keep in mind

Scheduled functions are still Netlify Functions under the hood, so they share the same limits:

  • 10-second execution time on the free plan (26 seconds on paid)
  • They consume compute credits (5 credits per GB-hour)
  • The schedule can't fire more often than once per minute

For most use cases — daily rebuilds, hourly syncs — these limits are more than enough.

Perttu Lähteenlahti

Perttu Lähteenlahti

Developer Advocate at RevenueCat and creator of Netli.fyi. Building on Netlify since 2019. Writes from hands-on experience deploying dozens of production sites.

Manage Netlify on the go

Download Netli.fyi and monitor your sites, check deploys, and manage your projects from anywhere.

Related articles