superset-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-superset] serenajiang commented on a change in pull request #8139: [sqllab] add retries for stop_query
Date Tue, 03 Sep 2019 17:17:01 GMT
serenajiang commented on a change in pull request #8139: [sqllab] add retries for stop_query
URL: https://github.com/apache/incubator-superset/pull/8139#discussion_r320385315
 
 

 ##########
 File path: superset/sql_lab.py
 ##########
 @@ -70,23 +70,31 @@ def handle_query_error(msg, query, session, payload=None):
     return payload
 
 
-def get_query(query_id, session, retry_count=5):
-    """attemps to get the query and retry if it cannot"""
-    query = None
-    attempt = 0
-    while not query and attempt < retry_count:
-        try:
-            query = session.query(Query).filter_by(id=query_id).one()
-        except Exception:
-            attempt += 1
-            logging.error(f"Query with id `{query_id}` could not be retrieved")
-            stats_logger.incr("error_attempting_orm_query_" + str(attempt))
-            logging.error(f"Query {query_id}: Sleeping for a sec before retrying...")
-            sleep(1)
-    if not query:
-        stats_logger.incr("error_failed_at_getting_orm_query")
+def backoff_handler(details):
+    query_id = details["kwargs"]["query_id"]
+    logging.error(f"Query with id `{query_id}` could not be retrieved")
+    stats_logger.incr("error_attempting_orm_query_{}".format(details["tries"] - 1))
+    logging.error(f"Query {query_id}: Sleeping for a sec before retrying...")
+
+
+def giveup_handler(details):
+    stats_logger.incr("error_failed_at_getting_orm_query")
+
+
+@backoff.on_exception(
+    backoff.constant,
+    SqlLabException,
+    interval=1,
+    on_backoff=backoff_handler,
+    on_giveup=giveup_handler,
+    max_tries=5,
+)
+def get_query(query_id, session):
 
 Review comment:
   nope, all good.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Mime
View raw message