Defining schedules
You can scaffold schedules from the command line by running dg scaffold defs dagster.schedule <path/to/schedule_file.py>. For more information, see the dg CLI docs.
Defining basic schedules
The following examples demonstrate how to define some basic schedules.
- Using ScheduleDefinition
- Using @schedule
This example demonstrates how to define a schedule using ScheduleDefinition that will run all assets every day at midnight.
basic_schedule = dg.ScheduleDefinition(
name="basic_schedule", cron_schedule="0 0 * * *", target="*"
)
The cron_schedule argument accepts standard cron expressions. If your croniter dependency's version is >= 1.0.12, the argument will also accept the following:
@daily@hourly@monthly
This example demonstrates how to define a schedule using @dg.schedule, which provides more flexibility than ScheduleDefinition. For example, you can configure job behavior based on its scheduled run time or emit log messages.
@schedule(target="*", cron_schedule="0 0 * * *")
def basic_schedule(): ...
# things the schedule does, like returning a RunRequest or SkipReason
The cron_schedule argument accepts standard cron expressions. If your croniter dependency's version is >= 1.0.12, the argument will also accept the following:
@daily@hourly@monthly