Defining schedules
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 a job every day at midnight. While this example uses op jobs, the same approach will work with asset jobs.
@job
def my_job(): ...
basic_schedule = ScheduleDefinition(job=my_job, cron_schedule="0 0 * * *")
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(job=my_job, 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
Emitting log messages from schedule evaluation
This example demonstrates how to emit log messages from a schedule during its evaluation function. These logs will be visible in the UI when you inspect a tick in the schedule's tick history.
@schedule(job=my_job, cron_schedule="* * * * *")
def logs_then_skips(context):
context.log.info("Logging from a schedule!")
return SkipReason("Nothing to do")
Schedule logs are stored in your Dagster instance's compute log storage. You should ensure that your compute log storage is configured to view your schedule logs.