My organization has been using a DAG that only runs on a manual trigger for quite some time. Any external resources that the dag interacts with are parameterized by the execution date {{ ds_nodash }}.
We recently converted this dag to run on a weekly schedule and I came to find that the airflow "scheduler triggers a DAG run at the end of its schedule period, rather than at the beginning of it". I wasn't expecting this at all. I'm not trying to debate airflow's schedulers design, but instead I'm looking for some advice on how to write DAGs that work both by manual trigger AND by a scheduled interval.
Here are my specific dilemmas:
- To get around the fact that the scheduler uses the beginning of the period I could use {{ next_ds_nodash }}, but then the manually triggered dag will never be parameterized by its own execution date
- When manually triggered we wanted to look at another file 7 days in the past: {{ execution_date - macros.timedelta(days=7)).strftime("%Y%m%d") }}. When schedule triggered this now looks 14 days in the past. How can I accomplish both?
I'm not looking for direct solutions to my dilemmas, but instead wondering if my intention of having a DAG run on a schedule and manually is actually quite out of the ordinary? If not what are specific solutions to my dilemmas OR some best practices for writing DAGs that you can manually trigger AND schedule.