Differential D8684 Diff 40807 examples/docs_snippets/docs_snippets/concepts/partitions_schedules_sensors/schedules/schedules.py
Changeset View
Changeset View
Standalone View
Standalone View
examples/docs_snippets/docs_snippets/concepts/partitions_schedules_sensors/schedules/schedules.py
import datetime | import datetime | ||||
from dagster import daily_schedule, schedule | from dagster import daily_schedule, schedule | ||||
# start_partition_based_schedule | # start_partition_based_schedule | ||||
@daily_schedule( | @daily_schedule( | ||||
pipeline_name="my_pipeline", | pipeline_name="my_pipeline", | ||||
start_date=datetime.datetime(2021, 1, 1), | start_date=datetime.datetime(2021, 1, 1), | ||||
execution_time=datetime.time(11, 0), | execution_time=datetime.time(11, 0), | ||||
execution_timezone="US/Central", | execution_timezone="US/Central", | ||||
) | ) | ||||
def my_daily_schedule(date): | def my_daily_schedule(date): | ||||
return {"solids": {"process_data_for_date": {"config": {"date": date.strftime("%Y-%m-%d")}}}} | return { | ||||
"solids": { | |||||
"process_data_for_date": { | |||||
"config": {"date": date.strftime("%Y-%m-%d")} | |||||
} | |||||
} | |||||
} | |||||
# end_partition_based_schedule | # end_partition_based_schedule | ||||
# start_non_partition_based_schedule | # start_non_partition_based_schedule | ||||
@schedule(cron_schedule="0 1 * * *", pipeline_name="my_pipeline", execution_timezone="US/Central") | @schedule( | ||||
cron_schedule="0 1 * * *", | |||||
pipeline_name="my_pipeline", | |||||
execution_timezone="US/Central", | |||||
) | |||||
def my_schedule(_context): | def my_schedule(_context): | ||||
return {"solids": {"process_data": {"config": {"dataset_name": "my_dataset"}}}} | return { | ||||
"solids": {"process_data": {"config": {"dataset_name": "my_dataset"}}} | |||||
} | |||||
# end_non_partition_based_schedule | # end_non_partition_based_schedule | ||||
# start_execution_time | # start_execution_time | ||||
@schedule(cron_schedule="0 1 * * *", pipeline_name="my_pipeline", execution_timezone="US/Central") | @schedule( | ||||
cron_schedule="0 1 * * *", | |||||
pipeline_name="my_pipeline", | |||||
execution_timezone="US/Central", | |||||
) | |||||
def my_execution_time_schedule(context): | def my_execution_time_schedule(context): | ||||
date = context.scheduled_execution_time.strftime("%Y-%m-%d") | date = context.scheduled_execution_time.strftime("%Y-%m-%d") | ||||
return { | return { | ||||
"solids": { | "solids": { | ||||
"process_data": {"config": {"dataset_name": "my_dataset", "execution_date": date}} | "process_data": { | ||||
"config": { | |||||
"dataset_name": "my_dataset", | |||||
"execution_date": date, | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
# end_execution_time | # end_execution_time | ||||
# start_timezone | # start_timezone | ||||
@daily_schedule( | @daily_schedule( | ||||
pipeline_name="my_data_pipeline", | pipeline_name="my_data_pipeline", | ||||
start_date=datetime.datetime(2020, 1, 1), | start_date=datetime.datetime(2020, 1, 1), | ||||
execution_time=datetime.time(9, 0), | execution_time=datetime.time(9, 0), | ||||
execution_timezone="US/Pacific", | execution_timezone="US/Pacific", | ||||
) | ) | ||||
def my_timezone_schedule(date): | def my_timezone_schedule(date): | ||||
return { | return { | ||||
"solids": { | "solids": { | ||||
"process_data_for_date": {"config": {"date": date.strftime("%Y-%m-%d %H:%M:%S")}} | "process_data_for_date": { | ||||
"config": {"date": date.strftime("%Y-%m-%d %H:%M:%S")} | |||||
} | |||||
} | } | ||||
} | } | ||||
# end_timezone | # end_timezone |