---
title: Schedules
slug: schedules
summary: Run a Function on a cron schedule, check that it is registered, run it on demand, and keep it healthy when runs fail.
---

# Schedules

A schedule runs a Function on its own, at the times a cron expression names. You declare it in code with `schedule=` on the Function, push to `main`, and LimiLake fires a Function Run at each time. There is no separate scheduler to configure and no CLI command that creates a schedule.

You need `editor` or `owner` on the Workspace to push a schedule. Any member, `viewer` included, can see schedules and runs and start a run on demand. Only an `owner` can resume a schedule that LimiLake paused.

## 1. Declare the schedule

Create a Function, or open an existing one:

```bash
limilake add function nightly-invoices
```

Add `schedule=` to the `limilake.function(...)` call in `functions/nightly-invoices/function.py`:

```python
import limilake
from limilake import logger

fn = limilake.function(
    id="123e4567-e89b-42d3-a456-426614174001",  # keep the id the CLI generated
    name="nightly-invoices",
    description="Count yesterday's invoices every night",
    schedule="0 2 * * *",  # 02:00 UTC every day
    timeout="20m",
)


@fn.action
def run() -> dict[str, int]:
    rows = limilake.lake.query(
        "select count(*) as n from bronze.invoices where invoice_date = current_date - 1"
    )
    n = rows[0]["n"]
    logger.info(f"{n} invoices yesterday")
    return {"invoices": n}
```

A schedule runs the Function's `@fn.action` or `@fn.sync` handler:

- A Function with one of them runs that handler.
- A Function with both runs the `@fn.sync` handler on schedule.
- A Function with only HTTP routes cannot be scheduled. LimiLake ignores its `schedule=` and registers nothing.

A scheduled run receives an empty input object, so write the handler with no parameter, or read optional fields from the `dict` it receives. A scheduled run has no person behind it: `limilake.caller()` returns `None`.

`schedule=` must be a literal string in the call. An invalid expression makes the push fail with [`function_declaration_invalid`](./push-rejections.md#function_declaration_invalid), so a broken schedule never reaches `main`.

## 2. Write the cron expression

A schedule is either five cron fields or one alias. The five fields are minute (0 to 59), hour (0 to 23), day of the month (1 to 31), month (1 to 12 or `JAN` to `DEC`) and day of the week (0 to 7, where both 0 and 7 are Sunday, or `SUN` to `SAT`). Each field takes `*`, a value, a list (`1,15`), a range (`1-5`) or a step (`*/15`).

| Schedule | Runs (UTC) |
|---|---|
| `0 2 * * *` | Every day at 02:00 |
| `*/15 * * * *` | Every 15 minutes |
| `30 6 * * MON-FRI` | Monday to Friday at 06:30 |
| `0 3 1 * *` | The first day of every month at 03:00 |

| Alias | Same as |
|---|---|
| `@hourly` | `0 * * * *` |
| `@daily` or `@midnight` | `0 0 * * *` |
| `@weekly` | `0 0 * * 0` (Sunday at 00:00) |
| `@monthly` | `0 0 1 * *` |
| `@yearly` or `@annually` | `0 0 1 1 *` |

One Function has at most one schedule. A schedule fires at most once every 5 minutes: a cron that asks for more often is thinned to that pace.

## 3. Plan for UTC

A schedule declared in code always runs in UTC. `limilake.function(...)` has no time zone argument, and the cron is not shifted for daylight saving time.

Central European Time is UTC+1 in winter and UTC+2 in summer, so one cron cannot hit the same local time all year. Suppose you want a report at 07:00 Berlin time on weekdays:

- `0 6 * * 1-5` runs at 07:00 in winter and 08:00 in summer.
- `0 5 * * 1-5` runs at 06:00 in winter and 07:00 in summer.

If the exact local time matters, fire at both candidate hours and let the code keep the right one:

```python
from datetime import datetime
from zoneinfo import ZoneInfo

import limilake

fn = limilake.function(
    id="123e4567-e89b-42d3-a456-426614174002",
    name="morning-report",
    schedule="0 5,6 * * 1-5",  # 05:00 and 06:00 UTC, Monday to Friday
)


@fn.action
def run() -> dict[str, str]:
    if datetime.now(ZoneInfo("Europe/Berlin")).hour != 7:
        return {"skipped": "not 07:00 in Berlin"}
    # build and send the report here
    return {"status": "sent"}
```

One of the two runs each morning returns at once and costs only a few seconds of a sandbox.

## 4. Publish and check that it is registered

A schedule goes live when the commit that declares it is on `main` and LimiLake has indexed it. Nothing else turns it on:

```bash
git add -- functions/nightly-invoices/function.py
git commit -m "Run nightly invoices at 02:00 UTC"
git push origin HEAD:main
limilake function show functions/nightly-invoices/function.py --workspace finance
```

`limilake function show` reports `triggers: 1` once the schedule is registered, along with `has_action`, `has_sync` and `timeout_seconds`. In the web app, open the Workspace and choose **Runs**: the schedule is listed with its cadence, **Next run** and **Last run**.

Changing the expression and pushing again moves the next run to the new time. Removing `schedule=`, or the Function, and pushing stops it. A schedule on another branch never fires.

## 5. Run it now

You can start a run at any time without waiting for the schedule. Both commands queue a Function Run of the latest `main`, print its `run_id` and return without waiting:

```bash
limilake function invoke nightly-invoices --workspace finance
limilake function trigger fire nightly-invoices --workspace finance
```

| Command | Recorded as | Counts toward failure notices and auto-pause |
|---|---|---|
| `limilake function invoke` | A manual run (reason `manual`) | No |
| `limilake function trigger fire` | A scheduled run (reason `schedule`) | Yes |

Use `invoke` to try the Function. Use `trigger fire` when you want the run to behave like a real scheduled run, for example to check that a fix clears a failing schedule. Both take `--input` and, for a Function with both handlers, `--handler action` or `--handler sync`. The **Run now** button in the Runs view starts a manual run.

To run schedules on your own machine while you develop, `limilake function serve --schedules` also fires them locally.

## Limits and defaults of a run

| Setting | Default | Range | How to change it |
|---|---|---|---|
| How long one run may take | 30 minutes | 1 minute to 24 hours | `timeout=` on the Function, as seconds (`7200`) or a duration (`"90m"`, `"2h"`) |
| Scheduled runs at the same time | 1 | Fixed | A fire while the previous run is still running is skipped, not queued |
| How often a schedule fires | At most every 5 minutes | Fixed | Write a slower cron |

A run that passes its timeout ends with status `timed_out`. The timeout applies to manual runs too.

`concurrency_limit=` (default 4) limits concurrent calls to the Function's HTTP routes. It does not change how scheduled runs overlap.

A schedule whose Function calls `agent.run()` uses the same rules. Each fire pays for a sandbox and a full Agent loop, so run it every 15 minutes or slower, and daily where you can. See [Scheduling an agent](./agents.md#scheduling-an-agent).

## See the runs

```bash
limilake function logs functions/nightly-invoices/function.py --workspace finance
limilake function watch functions/nightly-invoices/function.py <run-id> --workspace finance
limilake execution logs <execution-id>
```

`function logs` lists the latest 20 runs (`--limit` changes that) with each run's `status`, `reason`, `error`, `result` and `execution_id`. A run ends as `completed`, `failed`, `timed_out`, `skipped` or `cancelled`. `function watch` follows one run until it ends. `execution logs` prints the log lines the run wrote with `limilake.logger`.

The **Runs** view in the web app shows the same runs per Workspace, with each schedule's next and last run.

## When a run fails

When a Function has failed for a whole day, every active `owner` of the Workspace gets one notice in the web app and by email. That is when its newest scheduled run failed or timed out, the first failed run since its last successful one ended at least 24 hours ago, and no scheduled run has succeeded since. In the web app the notice says the Function keeps failing and opens the Runs view. The email also says since when it has been failing and how many scheduled runs in a row failed, gives a short excerpt of the latest error with likely secrets removed, and links to the Runs view. Each person's notification settings decide the channels; both are on by default, and the same rule holds for both.

A run that fails and is followed by a successful run within the day sends no notice; the Runs view shows every failure. The day is counted from the first failed run, so a Function that runs less often, such as weekly, is reported a day after it failed. Each failing stretch is reported once, however long it lasts. A successful run ends it, and a new day of failures after that sends a new notice. An owner gets at most 5 such notices a day across the Tenant's Functions. Manual runs and Agent runs never count toward a notice.

## Auto-pause

LimiLake pauses a schedule that keeps failing. A schedule is paused when all of these hold:

- it had at least two scheduled runs that ended in the last 3 days,
- every one of them failed or timed out, and
- it also ran before those 3 days, so it has been failing for the whole window.

A single failure never pauses a schedule, one success in the window prevents it, and a schedule younger than 3 days is never paused.

When a schedule is paused, it stops firing, and each owner gets one notice that it was paused and no further failure notices. The Runs view marks it **Paused after repeated failures**.

To resume it, an `owner` opens the Workspace, chooses **Runs** and selects **Resume** on the schedule. Pushing a fix does not resume it by itself. After you resume:

- the schedule fires next at its next scheduled time from now,
- the fires it missed while paused do not run, and
- only runs after the resume count toward pausing it again.

There is no CLI command to pause or resume a schedule. To stop a schedule yourself, remove `schedule=` and push.

Schedules are the only automatic trigger: a Function cannot be started by an event such as a new file or a table change.

## Next steps

- [Functions](./functions.md): handlers and publishing. Access modes are in the
  [Functions reference](./functions-reference.md#access-and-execution-identity).
- [Scheduling an agent](./agents.md#scheduling-an-agent): the check-then-invoke pattern for scheduled Agents.
- [Sandboxes](./sandboxes.md): where a scheduled run executes and what it can reach.
