[fix] warm up cache error handling (#9560)

Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
John Bodley 2020-04-16 15:19:32 -07:00 committed by GitHub
parent 7b11b44abe
commit 074e3653e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -1694,6 +1694,8 @@ class Superset(BaseSupersetView):
.all()
)
result = []
for slc in slices:
try:
form_data = get_form_data(slc.id, use_slice_data=True)[0]
@ -1707,15 +1709,18 @@ class Superset(BaseSupersetView):
form_data=form_data,
force=True,
)
obj.get_json()
payload = obj.get_payload()
error = payload["error"]
status = payload["status"]
except Exception as ex:
logger.exception("Failed to warm up cache")
return json_error_response(utils.error_msg_from_exception(ex))
return json_success(
json.dumps(
[{"slice_id": slc.id, "slice_name": slc.slice_name} for slc in slices]
error = utils.error_msg_from_exception(ex)
status = None
result.append(
{"slice_id": slc.id, "viz_error": error, "viz_status": status}
)
)
return json_success(json.dumps(result))
@has_access_api
@expose("/favstar/<class_name>/<obj_id>/<action>/")

View File

@ -610,7 +610,9 @@ class CoreTests(SupersetTestCase):
def test_warm_up_cache(self):
slc = self.get_slice("Girls", db.session)
data = self.get_json_resp("/superset/warm_up_cache?slice_id={}".format(slc.id))
self.assertEqual(data, [{"slice_id": slc.id, "slice_name": slc.slice_name}])
self.assertEqual(
data, [{"slice_id": slc.id, "viz_error": None, "viz_status": "success"}]
)
data = self.get_json_resp(
"/superset/warm_up_cache?table_name=energy_usage&db_name=main"