Skip to content

Commit

Permalink
make client global
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmcreynolds committed Feb 12, 2023
1 parent 2dfc4b4 commit 333a4a7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ def new_httpx_client():
config.http_client_timeout_all,
connect=config.http_client_timeout_connect,
pool=config.http_client_timeout_pool)

return httpx.AsyncClient(
base_url="http://prefect_server:4200", limits=limits, timeout=timeout)
client = new_httpx_client()

@app.on_event('shutdown')
async def shutdown_event():
global client
await client.aclose()


Expand Down Expand Up @@ -141,6 +143,7 @@ async def endpoint_reverse_proxy(request: Request,
# this is ugly, but we try and keep the service running by killing
# the client and starting fresh
logger.error("Exception from http client", exc_info=1)
global client
await client.aclose()
client = new_httpx_client()
raise HTTPException(
Expand All @@ -155,7 +158,7 @@ async def close(resp: StreamingResponse):
async def _reverse_proxy(request: Request, scopes: Optional[List[str]] = None) -> StreamingResponse:
# # cheap and quick scope feature
# if scopes and request.method.lower() in sceope

global client

url = httpx.URL(path=request.url.path,
query=request.url.query.encode("utf-8"))
Expand Down

0 comments on commit 333a4a7

Please sign in to comment.