Commit 76bb9cab by Karsa Zoltán István

linter

parent b53e8296
......@@ -9,7 +9,7 @@ from sredis.sredis import (
set_token,
create_superpuser,
get_rtokens,
reset
reset,
)
import logging
import requests
......@@ -60,7 +60,9 @@ def proxy_get(
def proxy_delete(
server_path: str = "/", username=Depends(get_current_user), datacenter: str = ""
):
return proxy_datacenters(server_path, username, method="DELETE", datacenter=datacenter)
return proxy_datacenters(
server_path, username, method="DELETE", datacenter=datacenter
)
@app.post("/lb/rr/{server_path:path}")
......@@ -89,6 +91,7 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
set_token(username, str(token.datacenter), str(token.token))
return tokens
@app.get("/tokens/")
def get_tokens(username=Depends(get_current_user)):
return get_rtokens(username=username)
......@@ -29,6 +29,10 @@ help = "Start the microservice on port 6973"
shell = "poetry run uvicorn main:app --host 0.0.0.0 --port 8080 --workers 8 --log-level critical"
help = "Start the prod deployment"
[tool.poe.tasks.stress]
shell = "poetry run uvicorn main:app --host 0.0.0.0 --port 6973 --workers 4"
help = "Start the prod deployment"
[tool.poe.tasks.lint]
shell = "poetry run black . && poetry run ruff --fix . "
help = "Lint the most important parts of the microservice with black"
......
......@@ -9,12 +9,13 @@ import random
r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True)
def reset():
print("Reset OK")
r.set("datacenters_cnt", 1)
all_keys = r.hgetall("datacenters_hash")
if all_keys.keys():
r.hdel("datacenters_hash",*list(all_keys.keys()))
r.hdel("datacenters_hash", *list(all_keys.keys()))
r.delete("rrlist")
pipe = r.pipeline()
......@@ -22,6 +23,7 @@ def reset():
pipe.rpush("rrlist", dc)
pipe.execute()
def add_datacenter(datacenter: str):
cnt = int(r.get("datacenters_cnt"))
r.hset("datacenters_hash", cnt, datacenter)
......@@ -29,6 +31,7 @@ def add_datacenter(datacenter: str):
r.set("roundrobin_cnt", 1)
r.rpush("rrlist", datacenter)
def rr_get():
rr = r.rpoplpush("rrlist", "rrlist")
return rr
......@@ -43,19 +46,22 @@ def wr_get(centers: DataCenterSchema):
def set_token(username: str, datacenter: str, token: str):
r.hset(f"tokens:{username}", datacenter, token)
def get_rtoken(username: str, datacenter: str):
return r.hget(f"tokens:{username}", datacenter)
def get_rtokens(username: str):
center_ids = list(r.hgetall("datacenters_hash").keys())
tokens = []
for id in center_ids:
token = { }
token = {}
token["datacenter"] = r.hget("datacenters_hash", id)
token["token"] = get_rtoken(username=username, datacenter=token["datacenter"])
tokens.insert(0, token)
return tokens
def get_datacenter_token(username: str, datacenter: str):
return str(r.hget(f"tokens:{username}", datacenter))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment