Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
balancer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
76bb9cab
authored
May 17, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linter
parent
b53e8296
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
4 deletions
+17
-4
main.py
+5
-2
pyproject.toml
+4
-0
sredis/sredis.py
+8
-2
stresstest/main.py
+0
-0
No files found.
main.py
View file @
76bb9cab
...
...
@@ -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
)
pyproject.toml
View file @
76bb9cab
...
...
@@ -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"
...
...
sredis/sredis.py
View file @
76bb9cab
...
...
@@ -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
))
...
...
stresstest/main.py
View file @
76bb9cab
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment