uranusjr commented on a change in pull request #18439:
URL: https://github.com/apache/airflow/pull/18439#discussion_r723779104
##########
File path: airflow/utils/db.py
##########
@@ -626,27 +629,88 @@ def check_migrations(timeout):
:param timeout: Timeout for the migration in seconds
:return: None
"""
- from alembic.runtime.migration import MigrationContext
+ ticker = 0
+ while True:
+ source_heads = get_source_heads()
+ db_heads = get_db_heads()
+ if source_heads == db_heads:
+ break
+ if ticker >= timeout:
+ raise TimeoutError(
+ f"There are still unapplied migrations after {ticker} seconds.
"
+ f"Migration Head(s) in DB: {db_heads} | Migration Head(s) in
Source Code: {source_heads}"
+ )
+ ticker += 1
+ time.sleep(1)
+ log.info('Waiting for migrations... %s second(s)', ticker)
Review comment:
Maybe?
```suggestion
for ticker in range(timeout):
source_heads = get_source_heads()
db_heads = get_db_heads()
if source_heads == db_heads:
return
time.sleep(1)
log.info('Waiting for migrations... %s second(s)', ticker)
raise TimeoutError(
f"There are still unapplied migrations after {timeout} seconds. "
f"Migration Head(s) in DB: {db_heads} | Migration Head(s) in Source
Code: {source_heads}"
)
```
(This emits one extra *Waiting for migrations* line; we can eliminate that
with an additional `if` check but I don't feel it's worthwhile.)
##########
File path: airflow/utils/db.py
##########
@@ -626,27 +629,88 @@ def check_migrations(timeout):
:param timeout: Timeout for the migration in seconds
:return: None
"""
- from alembic.runtime.migration import MigrationContext
+ ticker = 0
+ while True:
+ source_heads = get_source_heads()
+ db_heads = get_db_heads()
+ if source_heads == db_heads:
+ break
+ if ticker >= timeout:
+ raise TimeoutError(
+ f"There are still unapplied migrations after {ticker} seconds.
"
+ f"Migration Head(s) in DB: {db_heads} | Migration Head(s) in
Source Code: {source_heads}"
+ )
+ ticker += 1
+ time.sleep(1)
+ log.info('Waiting for migrations... %s second(s)', ticker)
+
+
+def get_source_heads():
+ """
+ Function to get the current migration head in the source code.
+
+ :return: List of migration head(s)
Review comment:
But the return value is actually a set? :p
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]