xuganyu96 commented on issue #31818:
URL: https://github.com/apache/airflow/issues/31818#issuecomment-1585827854

   # How database check is performed
   The `airflow.cli.commands.db_command.check` function calls the function 
`airflow.utils.db.check`, which in turns uses the provided session to execute a 
trivial SQL command:
   
   ```python
   @provide_session
   def check(session: Session = NEW_SESSION):
       """
       Checks if the database works.
   
       :param session: session of the sqlalchemy
       """
       session.execute(text("select 1 as is_alive;"))
       log.info("Connection successful.")
   ```
   
   The DB check command will let the `execute` function call raise unhandled 
exception as a "fail".
   
   For implementing retry, one approach would be to catch the exception raised 
by `execute` each time and update the retry status in the "except" clause.
   
   Note that `airflow.utils.db.check` is not used anywhere else, so it is also 
possible to refactor `db.check` in a major way, such as letting it return a 
boolean indicating whether the check is successful, which avoids using (what I 
think to be rather unsavory) try-catch blocks and makes the logic more straight 
forward, but oh well.


-- 
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]

Reply via email to