Skip to content

Commit

Permalink
Adds retry on taskinstance retrieval lock (#20030)
Browse files Browse the repository at this point in the history
Fixes: #19832

Co-authored-by: Jaroslaw Potiuk <jarek@Jaroslaws-MacBook-Pro.local>
(cherry picked from commit 78c815e)
  • Loading branch information
potiuk authored and jedcunningham committed Jan 20, 2022
1 parent 03be5a1 commit 94865f9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion airflow/models/taskinstance.py
Expand Up @@ -91,6 +91,7 @@
from airflow.utils.net import get_hostname
from airflow.utils.operator_helpers import context_to_airflow_vars
from airflow.utils.platform import getuser
from airflow.utils.retries import run_with_db_retries
from airflow.utils.session import create_session, provide_session
from airflow.utils.sqlalchemy import ExtendedJSON, UtcDateTime
from airflow.utils.state import DagRunState, State
Expand Down Expand Up @@ -723,7 +724,9 @@ def refresh_from_db(self, session=None, lock_for_update=False) -> None:
)

if lock_for_update:
ti: Optional[TaskInstance] = qry.with_for_update().first()
for attempt in run_with_db_retries(logger=self.log):
with attempt:
ti: Optional[TaskInstance] = qry.with_for_update().first()
else:
ti = qry.first()
if ti:
Expand Down

0 comments on commit 94865f9

Please sign in to comment.