robdiciuccio commented on a change in pull request #11499: URL: https://github.com/apache/incubator-superset/pull/11499#discussion_r537845484
########## File path: superset/utils/async_query_manager.py ########## @@ -0,0 +1,180 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import json +import logging +import uuid +from typing import Any, Dict, List, Optional, Tuple + +import jwt +import redis +from flask import Flask, Request, Response, session + +logger = logging.getLogger(__name__) + + +class AsyncQueryTokenException(Exception): + pass + + +class AsyncQueryJobException(Exception): + pass + + +def build_job_metadata(channel_id: str, job_id: str, **kwargs: Any) -> Dict[str, Any]: + return { + "channel_id": channel_id, + "job_id": job_id, + "user_id": session.get("user_id"), + "status": kwargs.get("status"), + "errors": kwargs.get("errors", []), + "result_url": kwargs.get("result_url"), + } + + +def parse_event(event_data: Tuple[str, Dict[str, Any]]) -> Dict[str, Any]: + event_id = event_data[0] + event_payload = event_data[1]["data"] + return {"id": event_id, **json.loads(event_payload)} + + +class AsyncQueryManager: Review comment: This class handles initialization of the async event subsystem, including Redis streams and JWT auth tokens. It also provides methods to read/write data to the event streams. ---------------------------------------------------------------- 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: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
