# Cloud cron jobs with Netlify Scheduled Functions

> Learn how to set up cloud cron jobs with Netlify Scheduled Functions, scheduling runs with @hourly, @daily, or a cron expression in netlify.toml.

Author: Flavio Copes | Published: 2022-04-28 | Canonical: https://flaviocopes.com/netlify-cloud-cron-jobs/

[Netlify](https://flaviocopes.com/netlify/) Scheduled Functions allow us to do some interesting things.

Here's how to set them up.

Create a [serverless function](https://flaviocopes.com/netlify-functions/) in `netlify/functions` in your repository, for example `test.js`:

> `netlify/functions/test.js`

```js
exports.handler = (event, context) => {
  //do something
  return { statusCode: 200 }
}
```

Then in `netlify.toml` (create this file if you don't have it yet) configure how frequently you want this Netlify Scheduled Function to run:

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

Alternatively you can set this in the function itself, with no need for this entry:

```js
const handler = (event, context) => {
  //do something
  return { statusCode: 200 }
}

exports.handler = schedule('@hourly', handler)
```

`@hourly` runs every hour at minute 0
`@daily` runs every day at 00:00
`@weekly` runs every Sunday at 00:00

`@monthly` and `@yearly` are available too.

You can also use a cron expression, like `5 4 * * *` or any other expression ([crontab guru](https://crontab.guru) is your friend)

You can also invoke a function manually using `netlify functions:invoke test` where `test` is the name of the function.

You can use Netlify Scheduled Functions for many different use cases.

I set a Netlify Scheduled Function to auto-deploy the repository every day to post a schedule blog post, for which I set the publishing date in advance. 

I use the [Fetch API](https://flaviocopes.com/fetch-api/) to call the deploy webhook so I can do [automatic deploys on Netlify](https://flaviocopes.com/netlify-auto-deploy/).
