You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "daniel-dylag-openx (via GitHub)" <gi...@apache.org> on 2023/09/01 17:56:16 UTC
[GitHub] [airflow] daniel-dylag-openx opened a new pull request, #34021: Fix manual task triggering scheduled tasks
daniel-dylag-openx opened a new pull request, #34021:
URL: https://github.com/apache/airflow/pull/34021
Fixes #33949
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
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 an 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/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] daniel-dylag-openx commented on a diff in pull request #34021: Fix manual task triggering scheduled tasks
Posted by "daniel-dylag-openx (via GitHub)" <gi...@apache.org>.
daniel-dylag-openx commented on code in PR #34021:
URL: https://github.com/apache/airflow/pull/34021#discussion_r1313357554
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1300,9 +1300,16 @@ def _create_dag_runs_dataset_triggered(
)
def _should_update_dag_next_dagruns(
- self, dag: DAG, dag_model: DagModel, total_active_runs: int | None = None, *, session: Session
+ self, dag: DAG, dag_model: DagModel, last_dag_run: DagRun | None = None,
+ total_active_runs: int | None = None, *, session: Session
) -> bool:
- """Check if the dag's next_dagruns_create_after should be updated."""
+ """Check if the dag's next_dagruns_create_after should be updated.
+ If last_dag_run is defined, the update was triggered by a scheduling decision in this DAG run
+ """
+ # If last_dag_run is defined, schedule next only if last_dag_run is finished and was an automated run
+ if last_dag_run and not (last_dag_run.state in State.finished_dr_states and
+ last_dag_run.run_type in [DagRunType.SCHEDULED, DagRunType.BACKFILL_JOB]):
Review Comment:
this is the actual bugfix: previously we didn't check run type so manual runs were messing with scheduling decisions
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] daniel-dylag-openx commented on a diff in pull request #34021: Fix manual task triggering scheduled tasks
Posted by "daniel-dylag-openx (via GitHub)" <gi...@apache.org>.
daniel-dylag-openx commented on code in PR #34021:
URL: https://github.com/apache/airflow/pull/34021#discussion_r1313358099
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1465,11 +1472,9 @@ def _schedule_dag_run(
return callback
# TODO[HA]: Rename update_state -> schedule_dag_run, ?? something else?
schedulable_tis, callback_to_run = dag_run.update_state(session=session, execute_callbacks=False)
- # Check if DAG not scheduled then skip interval calculation to same scheduler runtime
- if dag_run.state in State.finished_dr_states:
Review Comment:
this part was pulled into `_should_update_dag_next_dagruns`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] daniel-dylag-openx commented on a diff in pull request #34021: Fix manual task triggering scheduled tasks
Posted by "daniel-dylag-openx (via GitHub)" <gi...@apache.org>.
daniel-dylag-openx commented on code in PR #34021:
URL: https://github.com/apache/airflow/pull/34021#discussion_r1313359646
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1300,9 +1300,16 @@ def _create_dag_runs_dataset_triggered(
)
def _should_update_dag_next_dagruns(
- self, dag: DAG, dag_model: DagModel, total_active_runs: int | None = None, *, session: Session
+ self, dag: DAG, dag_model: DagModel, last_dag_run: DagRun | None = None,
Review Comment:
there are 3 places where this method is used:
- when dag run is finished successfully
- when dag run fails
- when new dag runs were created
The first 2 cases are similar and we look at last dag run to make this decision, but in the 3rd case there is no previous dag run so I made this parameter optional and skip checking it if not provided
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] daniel-dylag-openx commented on a diff in pull request #34021: Fix scheduler logic to plan new dag runs by ignoring manual runs
Posted by "daniel-dylag-openx (via GitHub)" <gi...@apache.org>.
daniel-dylag-openx commented on code in PR #34021:
URL: https://github.com/apache/airflow/pull/34021#discussion_r1313357554
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -1300,9 +1300,16 @@ def _create_dag_runs_dataset_triggered(
)
def _should_update_dag_next_dagruns(
- self, dag: DAG, dag_model: DagModel, total_active_runs: int | None = None, *, session: Session
+ self, dag: DAG, dag_model: DagModel, last_dag_run: DagRun | None = None,
+ total_active_runs: int | None = None, *, session: Session
) -> bool:
- """Check if the dag's next_dagruns_create_after should be updated."""
+ """Check if the dag's next_dagruns_create_after should be updated.
+ If last_dag_run is defined, the update was triggered by a scheduling decision in this DAG run
+ """
+ # If last_dag_run is defined, schedule next only if last_dag_run is finished and was an automated run
+ if last_dag_run and not (last_dag_run.state in State.finished_dr_states and
+ last_dag_run.run_type in [DagRunType.SCHEDULED, DagRunType.BACKFILL_JOB]):
Review Comment:
This is the actual bugfix: previously we didn't check run type so manual runs were messing with scheduling decisions. Compare it with https://github.com/apache/airflow/blob/3ae6b4e86fe807c00bd736c59df58733df2b9bf9/airflow/models/dag.py#L2943 where exact same filtering is applied before eventually invoking `calculate_dagrun_date_fields` for filtered dag runs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] daniel-dylag-openx closed pull request #34021: Fix scheduler logic to plan new dag runs by ignoring manual runs
Posted by "daniel-dylag-openx (via GitHub)" <gi...@apache.org>.
daniel-dylag-openx closed pull request #34021: Fix scheduler logic to plan new dag runs by ignoring manual runs
URL: https://github.com/apache/airflow/pull/34021
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org