Skip to main content
Schedules represent a time frame to repeatedly run a Modal function. Cron jobs are a type of schedule, specified using the Unix cron tab syntax.

Constructor

modal.Cron(
    cron_string: str,
    timezone: str = "UTC",
)
Construct a schedule that runs according to a cron expression string.
cron_string
str
required
Cron expression string (e.g., “0 9 * * *”).
timezone
str
default:"UTC"
Timezone for the schedule (e.g., “America/New_York”).

Usage

import modal
app = modal.App()

@app.function(schedule=modal.Cron("* * * * *"))
def f():
    print("This function will run every minute")

Examples

# Run at 4:05am UTC every night
modal.Cron("5 4 * * *")

# Run every Thursday at 9am UTC
modal.Cron("0 9 * * 4")

# Run daily at 6am New York time (accounts for daylight saving)
modal.Cron("0 6 * * *", timezone="America/New_York")
Create a schedule that runs every given time interval.

Constructor

modal.Period(
    *,
    years: int = 0,
    months: int = 0,
    weeks: int = 0,
    days: int = 0,
    hours: int = 0,
    minutes: int = 0,
    seconds: float = 0,
)
Construct a period-based schedule.
years
int
default:"0"
Number of years between runs.
months
int
default:"0"
Number of months between runs.
weeks
int
default:"0"
Number of weeks between runs.
days
int
default:"0"
Number of days between runs.
hours
int
default:"0"
Number of hours between runs.
minutes
int
default:"0"
Number of minutes between runs.
seconds
float
default:"0"
Number of seconds between runs. Only this parameter can be a float.

Usage

import modal
import math

app = modal.App()

@app.function(schedule=modal.Period(days=1))
def f():
    print("This function will run every day")

# More examples
modal.Period(hours=4)          # Runs every 4 hours
modal.Period(minutes=15)       # Runs every 15 minutes
modal.Period(seconds=math.pi)  # Runs every 3.14159... seconds

Notes

Only seconds can be a float. All other arguments are integers.
days=1 will trigger the function the same time every day. This does not have the same behavior as seconds=86400 since days have different lengths due to daylight savings and leap seconds.Similarly, using months=1 will trigger the function on the same day each month.
This behaves similar to the dateutil package.

Build docs developers (and LLMs) love