Configuring job behavior based on scheduled run time
This example demonstrates how to use run config to vary the behavior of a job based on its scheduled run time.
@dg.op(config_schema={"scheduled_date": str})
def configurable_op(context: dg.OpExecutionContext):
context.log.info(context.op_config["scheduled_date"])
@dg.job
def configurable_job():
configurable_op()
@dg.schedule(job=configurable_job, cron_schedule="0 0 * * *")
def configurable_job_schedule(context: dg.ScheduleEvaluationContext):
scheduled_date = context.scheduled_execution_time.strftime("%Y-%m-%d")
return dg.RunRequest(
run_key=None,
run_config={
"ops": {"configurable_op": {"config": {"scheduled_date": scheduled_date}}}
},
tags={"date": scheduled_date},
)