-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deactivating DAGs which have been removed from files (#17121)
<!-- Thank you for contributing! Please make sure that your code changes are covered with tests. And in case of new features or big changes remember to adjust the documentation. Feel free to ping committers for the review! In case of existing issue, reference it using one of the following: closes: #ISSUE related: #ISSUE How to write a good git commit message: http://chris.beams.io/posts/git-commit/ --> Closes: #11901 Closes: #17516 Ensuring that the active DAGs in the DB are all actually present in their corresponding python files by reconciling the DB state and with the contents of a given DAG file on every parse operation. This _should_ prevent a lot of issues encountered when writing multiple DAGs per-file, renaming DAGs or dynamically generating DAGs based on a config file read at parse-time. This will cause a few other functional changes: 1) DAGs will disappear from the UI if an ImportError is introduced in the underlying file. 2) DAGs will no longer be re-marked as active if they are inactive / missing but the file is present. 3) DAGs could be incorrectly marked inactive if there's an unexpected parsing error (I guess this is a tradeoff between false-poitives and false-negatives) #### Validation: I have validated these changes in a local breeze environment with the following DAG: ```python from airflow.models import DAG from airflow import utils from airflow.operators.python import PythonOperator NUM_DAGS=1 def message(): print('Hello, world.') for i in range(NUM_DAGS): with DAG(f'dag-{i}', schedule_interval=None, start_date=utils.dates.days_ago(1)) as dag: task = PythonOperator( task_id='task', python_callable=message ) globals()[f"dag_{i}"] = dag ``` By changing the value of `NUM_DAGS` I can quickly change the number of DAG objects present in this file. Before this change, decreasing the value of `NUM_DAGS` would leave a bunch of stale DAGs in the UI. These could be triggered but would then fail as the executor was not able to load the specified task from the file. After implementing this change, stale DAGs disappear from the UI shortly after decreasing the value of `NUM_DAGS`. #### Questions: 1. Is there a good reason for Airflow to mark inactive DAGs as active if the file still exists? I looked through the [original PR which introduced this](https://github.com/apache/airflow/pull/5743/files) but couldn't find an explanation. 2. How significant is the performance hit incurred by updating the DAG table on every parse operation? 3. Will this change introduce any other functional changes that I haven't mentioned above? #### Follow up: If this PR is merged, we should also add some documentation which discusses dynamically generated DAGs, and explains how to generate multiple DAGs in a loop as shown in the example above.
- Loading branch information
1 parent
dc94ee2
commit e81f14b
Showing
4 changed files
with
57 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters