Skip to main content

Using schedules in Dagster projects

Prerequisites

Before following this guide, you will need to create a project with the create-dagster CLI.

Assets and jobs frequently use schedules that are instantiated elsewhere in the project.

For example, if you have created a new Dagster project with dg called my_project, you can define the schedules at src/my_project/defs/schedules.py:

Schedule binding can happen at any level of the defs hierarchy. If you moved asset_one in this example to a subdirectory, you could leave the existing schedules.py file at src/defs/schedules.py:

src
└── my_project
└── defs
├── assets
│ └── asset_one.py # contains def asset_one():
└── schedules.py # contains dg.schedule

Scaffolding schedules

To create a schedule dictionary like the above, you can run the following:

dg scaffold defs dagster.schedule path/to/schedules.py

which will create

src/<project_name>/defs/schedules.py
from typing import Union

import dagster as dg


@dg.schedule(cron_schedule="@daily", target="*")
def schedule(
context: dg.ScheduleEvaluationContext,
) -> Union[dg.RunRequest, dg.SkipReason]:
return dg.SkipReason(
"Skipping. Change this to return a RunRequest to launch a run."
)

and you can fill out the schedule dictionary as needed.