mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Handle errors when the MQ is down (#2494)
This commit is contained in:
parent
e14b74fdbf
commit
5f3484ac59
@ -1948,14 +1948,16 @@ class Superset(BaseSupersetView):
|
|||||||
@log_this
|
@log_this
|
||||||
def stop_query(self):
|
def stop_query(self):
|
||||||
client_id = request.form.get('client_id')
|
client_id = request.form.get('client_id')
|
||||||
query = db.session.query(models.Query).filter_by(
|
try:
|
||||||
client_id=client_id).one()
|
query = (
|
||||||
if query.user_id != g.user.id:
|
db.session.query(models.Query)
|
||||||
return json_error_response(
|
.filter_by(client_id=client_id).one()
|
||||||
"Only original author can stop the query.")
|
)
|
||||||
query.status = utils.QueryStatus.STOPPED
|
query.status = utils.QueryStatus.STOPPED
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return Response(201)
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
return self.json_response('OK')
|
||||||
|
|
||||||
@has_access_api
|
@has_access_api
|
||||||
@expose("/sql_json/", methods=['POST', 'GET'])
|
@expose("/sql_json/", methods=['POST', 'GET'])
|
||||||
@ -2003,18 +2005,33 @@ class Superset(BaseSupersetView):
|
|||||||
client_id=request.form.get('client_id'),
|
client_id=request.form.get('client_id'),
|
||||||
)
|
)
|
||||||
session.add(query)
|
session.add(query)
|
||||||
session.commit()
|
session.flush()
|
||||||
query_id = query.id
|
query_id = query.id
|
||||||
|
|
||||||
# Async request.
|
# Async request.
|
||||||
if async:
|
if async:
|
||||||
# Ignore the celery future object and the request may time out.
|
# Ignore the celery future object and the request may time out.
|
||||||
sql_lab.get_sql_results.delay(
|
try:
|
||||||
query_id, return_results=False,
|
sql_lab.get_sql_results.delay(
|
||||||
store_results=not query.select_as_cta)
|
query_id, return_results=False,
|
||||||
return json_success(json.dumps(
|
store_results=not query.select_as_cta)
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception(e)
|
||||||
|
msg = (
|
||||||
|
"Failed to start remote query on worker. "
|
||||||
|
"Tell your administrator to verify the availability of "
|
||||||
|
"the message queue."
|
||||||
|
)
|
||||||
|
query.status = QueryStatus.FAILED
|
||||||
|
query.error_message = msg
|
||||||
|
session.commit()
|
||||||
|
return json_error_response("{}".format(msg))
|
||||||
|
|
||||||
|
resp = json_success(json.dumps(
|
||||||
{'query': query.to_dict()}, default=utils.json_int_dttm_ser,
|
{'query': query.to_dict()}, default=utils.json_int_dttm_ser,
|
||||||
allow_nan=False), status=202)
|
allow_nan=False), status=202)
|
||||||
|
session.commit()
|
||||||
|
return resp
|
||||||
|
|
||||||
# Sync request.
|
# Sync request.
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user