A schedule is a Dagster definition that is used to execute a job at a fixed interval. Each time at which a schedule is evaluated is called a tick. The schedule definition can generate run configuration for the job on each tick.
Each schedule:
Targets a single job
Optionally defines a function that returns either:
One or more RunRequest objects. Each run request launches a run.
An optional SkipReason, which specifies a message which describes why no runs were requested
Dagster includes a scheduler, which runs as part of the dagster-daemon process. Once you have defined a schedule, see the dagster-daemon page for instructions on how to run the daemon in order to execute your schedules.
The cron_schedule argument accepts standard cron expressions. It also accepts "@hourly", "@daily", "@weekly", and "@monthly" if your croniter dependency's version is >= 1.0.12.
Schedules that provide custom run config and tags#
If you want to vary the behavior of your job based on the time it's scheduled to run, you can use the @schedule decorator, which decorates a function that returns run config based on a provided ScheduleEvaluationContext:
When you have a partitioned job that's partitioned by time, you can use the build_schedule_from_partitioned_job function to construct a schedule for it whose interval matches the spacing of partitions in your job.
For example, if you have a daily partitioned job that fills in a date partition of a table each time it runs, you likely want to run that job every day.
Each schedule tick of a partitioned job fills in the latest partition in the partition set that exists as of the tick time. Note that this implies that when the schedule submits a run on a particular day, it will typically be for the partition whose key corresponds to the previous day. For example, the schedule will fill in the 2020-04-01 partition on 2020-04-02. That's because each partition corresponds to a time window. The key of the partition is the start of the time window, but the partition isn't included in the list until its time window has completed. Waiting until the time window has finished before Kicking off a run means the run can process data from within that entire time window.
However, you can use the end_offset parameter of @daily_partitioned_config to change which partition is the most recent partition that is filled in at each schedule tick. Setting end_offset to 1 will extend the partitions forward so that the schedule tick that runs on day N will fill in day N's partition instead of day N-1, and setting end_offset to a negative number will cause the schedule to fill in earlier days' partitions. In general, setting end_offset to X will cause the partition that runs on day N to fill in the partition for day N - 1 + X. The same holds true for hourly, weekly, and monthly partitioned jobs, for their respective partition sizes.
You can use the minute_of_hour, hour_of_day, day_of_week, and day_of_month parameters of build_schedule_from_partitioned_job to control the timing of the schedule. For example, if you have a job that's partitioned by date, and you set minute_of_hour to 30 and hour_of_day to 1, the schedule would submit the run for partition 2020-04-01 at 1:30 AM on 2020-04-02.
You can also create a schedule for a static partition. The Partitioned Jobs concepts page also includes an example of how to define a static partitioned job. To define a schedule for a static partitioned job, we will construct a schedule from scratch, rather than using a helper function like build_schedule_from_partitioned_job this will allow more flexibility in determining which partitions should be run by the schedule.
For example, if we have the continents static partitioned job from the Partitioned Jobs concept page
You can customize the timezone in which your schedule executes by setting the execution_timezone parameter on your schedule to any tz timezone. Schedules with no timezone set run in UTC.
For example, the following schedule executes daily at 9AM in US/Pacific time:
Because of Daylight Savings Time transitions, it's possible to specify an execution time that does not exist for every scheduled interval. For example, say you have a daily schedule with an execution time of 2:30 AM in the US/Eastern timezone. On 2019/03/10, the time jumps from 2:00 AM to 3:00 AM when Daylight Savings Time begins. Therefore, the time of 2:30 AM did not exist for the day.
If you specify such an execution time, Dagster runs your schedule at the next time that exists. In the previous example, the schedule would run at 3:00 AM.
It's also possible to specify an execution time that exists twice on one day every year. For example, on 2019/11/03 in US/Eastern time, the hour from 1:00 AM to 2:00 AM repeats, so a daily schedule running at 1:30 AM has two possible times in which it could execute. In this case, Dagster will execute your schedule at the latter of the two possible times.
Hourly schedules will be unaffected by daylight savings time transitions - the schedule will continue to run exactly once every hour, even as the timezone changes. In the example above where the hour from 1:00 AM to 2:00 AM repeats, an hourly schedule running at 30 minutes past the hour would run at 12:30 AM, both instances of 1:30 AM, and then proceed normally from 2:30 AM on.
Dagster's resources system can be used with schedules to make it easier to interact with external systems or to make components of a schedule easier to plug in for testing purposes.
To specify resource dependencies, annotate the resource as a parameter to the schedule's function. Resources are provided by attaching them to your Definitions call.
Here, a resource is provided which helps a schedule generate a date string:
If you manually start or stop a schedule in the UI, that overrides any default status set in code.
Once the schedule is started, the schedule will begin executing immediately if you're running the dagster-daemon process as part of your deployment. Refer to the Troubleshooting section if your schedule has been started but isn't submitting runs.
In the UI, you can manually trigger a test evaluation of a schedule using a mock evaluation time and view the results.
On the overview page for a particular schedule, there is a Test schedule button. Clicking this button will perform a test evaluation of your schedule for a provided mock evaluation time, and show you the results of that evaluation.
Click Overview > Schedules.
Click the schedule you want to test.
Click the Test Schedule button, located near the top right corner of the page:
You'll be prompted to select a mock schedule evaluation time. As schedules are defined on a cadence, the evaluation times provided in the dropdown are past and future times along that cadence.
For example, let's say you're testing a schedule with a cadence of "Every day at X time". In the dropdown, you'd see five evaluation times in the future and five evaluation times in the past along that cadence.
After selecting an evaluation time, click the Evaluate button. A window containing the result of the evaluation will display:
If the evaluation was successful and a run request was produced, you can open the launchpad pre-scaffolded with the config corresponding to that run request.
To test a function decorated by the @schedule decorator, you can invoke the schedule definition like it's a regular Python function. The invocation will return run config, which can then be validated using the validate_run_config function. Below is a test for the configurable_job_schedule that we defined in an earlier section.
First, verify that the schedule has been included in a Definitions object. This ensures that the schedule is detectable and loadable by Dagster tools like the UI and CLI:
Next, using the UI, verify the schedule has been started:
Open the left sidenav and locate the job attached to the schedule. Schedules that have been started will have a green clock icon next to them:
If the schedule appears in the list but doesn't have the green clock icon, click the schedule. On the page that displays, use the toggle at the top of the page to mark it as running:
Next, verify that the UI has loaded the latest version of your schedule code:
Click Deployment in the top navigation.
In the Code locations tab, click Reload (local webserver) or Redeploy (Dagster Cloud).
If the webserver is unable to load the code location - for example, due to a syntax error - an error message with additional info will display in the left UI sidenav.
If the code location is loaded successfully but the schedule doesn't appear in the list of schedules, verify that the schedule is included in a Definitions object.
This section is applicable to Open Source (OSS) deployments.
If the schedule interval is correctly configured but runs aren't being created, it's possible that the dagster-daemon process isn't working correctly. If you haven't set up a Dagster daemon yet, refer to the Deployment guides for more info.
First, check that the daemon is running:
In the UI, click Deployment in the top navigation.
Click the Daemons tab.
Locate the Scheduler row.
The daemon process periodically sends out a hearbeat from the scheduler. If the scheduler daemon has a status of Not running, this indicates that there's an issue with your daemon deployment. If the daemon ran into an error that resulted in an exception, this error will often display in this tab.
If there isn't a clear error on this page or if the daemon should be sending heartbeans but isn't, move on to step two.
Next, check the logs from the daemon process. The steps to do this will depend on your deployment - for example, if you're using Kubernetes, you'll need to get the logs from the pod that's running the daemon. You should be able to search those logs for the name of your schedule (or SchedulerDaemon to see all logs associated with the scheduler) to gain an understanding of what's going wrong.
If the daemon output contains error indicating the schedule couldn't be found, verify that the daemon is using the same workspace.yaml file as the webserver. The daemon does not need to restart in order to pick up changes to the workspace.yaml file. Refer to the Workspace files documentation for more info.
If the logs don't indicate the cause of the issue, move on to step three.
Lastly, double-check your schedule code:
In the UI, open the schedule's Schedule details page by clicking the schedule in the left sidenav.
On this page, locate the latest tick for the schedule.
If there was an error trying to submit runs for the schedule, a red Failure badge should display in the Status column. Click the badge to display an error and stack trace describing the execution failure.
Still stuck? If these steps didn't resolve the issue, reach out in Slack or file an issue on GitHub.