mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-05 08:58:11 +08:00
#22 blackened code
This commit is contained in:
@@ -18,6 +18,7 @@ from cellxgene_gateway.cellxgene_exception import CellxgeneException
|
||||
from cellxgene_gateway.util import current_time_stamp
|
||||
from cellxgene_gateway.flask_util import querystring
|
||||
|
||||
|
||||
class CacheEntry:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -79,8 +80,10 @@ class CacheEntry:
|
||||
pid = self.pid
|
||||
if pid != None and self.status != "terminated":
|
||||
terminated = []
|
||||
|
||||
def on_terminate(p):
|
||||
terminated.append(p.pid)
|
||||
|
||||
p = psutil.Process(pid)
|
||||
children = p.children()
|
||||
for child in children:
|
||||
@@ -89,44 +92,46 @@ class CacheEntry:
|
||||
terminated.append(p.pid)
|
||||
p.terminate()
|
||||
psutil.wait_procs([p], callback=on_terminate)
|
||||
logging.getLogger("cellxgene_gateway").info(f"terminated {terminated}")
|
||||
logging.getLogger("cellxgene_gateway").info(
|
||||
f"terminated {terminated}"
|
||||
)
|
||||
self.status = "terminated"
|
||||
|
||||
def serve_content(self, path):
|
||||
gateway_basepath = (
|
||||
f"{env.external_protocol}://{env.external_host}/view/{self.key.pathpart}/"
|
||||
)
|
||||
gateway_basepath = f"{env.external_protocol}://{env.external_host}/view/{self.key.pathpart}/"
|
||||
subpath = path[len(self.key.pathpart) :] # noqa: E203
|
||||
|
||||
|
||||
if len(subpath) == 0:
|
||||
r = make_response(f"Redirect to {gateway_basepath}\n", 301)
|
||||
r.headers["location"] = gateway_basepath+querystring()
|
||||
r.headers["location"] = gateway_basepath + querystring()
|
||||
return r
|
||||
elif self.status == "loading":
|
||||
launch_time = datetime.datetime.fromtimestamp(self.launchtime)
|
||||
return render_template(
|
||||
"loading.html", launchtime=launch_time, all_output=self.all_output
|
||||
"loading.html",
|
||||
launchtime=launch_time,
|
||||
all_output=self.all_output,
|
||||
)
|
||||
|
||||
port = self.port
|
||||
cellxgene_basepath = f"http://127.0.0.1:{port}"
|
||||
headers = {}
|
||||
copy_headers = [
|
||||
'accept',
|
||||
'accept-encoding',
|
||||
'accept-language',
|
||||
'cache-control',
|
||||
'connection',
|
||||
'content-length',
|
||||
'content-type',
|
||||
'cookie',
|
||||
'host',
|
||||
'origin',
|
||||
'pragma',
|
||||
'referer',
|
||||
'sec-fetch-mode',
|
||||
'sec-fetch-site',
|
||||
'user-agent'
|
||||
"accept",
|
||||
"accept-encoding",
|
||||
"accept-language",
|
||||
"cache-control",
|
||||
"connection",
|
||||
"content-length",
|
||||
"content-type",
|
||||
"cookie",
|
||||
"host",
|
||||
"origin",
|
||||
"pragma",
|
||||
"referer",
|
||||
"sec-fetch-mode",
|
||||
"sec-fetch-site",
|
||||
"user-agent",
|
||||
]
|
||||
for h in copy_headers:
|
||||
if h in request.headers:
|
||||
@@ -135,20 +140,14 @@ class CacheEntry:
|
||||
full_path = cellxgene_basepath + subpath + querystring()
|
||||
|
||||
if request.method in ["GET", "HEAD", "OPTIONS"]:
|
||||
cellxgene_response = get(
|
||||
full_path, headers=headers
|
||||
)
|
||||
cellxgene_response = get(full_path, headers=headers)
|
||||
elif request.method == "PUT":
|
||||
cellxgene_response = put(
|
||||
full_path,
|
||||
headers=headers,
|
||||
data=request.data,
|
||||
full_path, headers=headers, data=request.data,
|
||||
)
|
||||
elif request.method == "POST":
|
||||
cellxgene_response = post(
|
||||
full_path,
|
||||
headers=headers,
|
||||
data=request.data,
|
||||
full_path, headers=headers, data=request.data,
|
||||
)
|
||||
else:
|
||||
raise CellxgeneException(
|
||||
@@ -169,9 +168,7 @@ class CacheEntry:
|
||||
resp_headers[h] = cellxgene_response.headers[h]
|
||||
|
||||
gateway_response = make_response(
|
||||
gateway_content,
|
||||
cellxgene_response.status_code,
|
||||
resp_headers,
|
||||
gateway_content, cellxgene_response.status_code, resp_headers,
|
||||
)
|
||||
|
||||
return gateway_response
|
||||
|
||||
Reference in New Issue
Block a user