You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/09/03 16:50:55 UTC

[GitHub] [incubator-superset] etr2460 commented on a change in pull request #8139: [sqllab] add retries for stop_query

etr2460 commented on a change in pull request #8139: [sqllab] add retries for stop_query
URL: https://github.com/apache/incubator-superset/pull/8139#discussion_r320373241
 
 

 ##########
 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:
   I assume this wasn't called anywhere before with the `retry_count` argument?

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