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
69d6fc05
authored
May 18, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
status setup
parent
76bb9cab
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
1 deletions
+32
-1
balancer/util.py
+2
-1
main.py
+8
-0
poetry.lock
+0
-0
pyproject.toml
+1
-0
sredis/sredis.py
+21
-0
No files found.
balancer/util.py
View file @
69d6fc05
...
...
@@ -42,4 +42,4 @@ def proxy_datacenters(
else
:
obj
[
"datacenter"
]
=
server
response
=
ORJSONResponse
(
obj
,
status_code
=
t_resp
.
status_code
)
return
response
return
response
\ No newline at end of file
main.py
View file @
69d6fc05
...
...
@@ -10,9 +10,11 @@ from sredis.sredis import (
create_superpuser
,
get_rtokens
,
reset
,
update_datacenter_status
,
)
import
logging
import
requests
from
fastapi_utils.tasks
import
repeat_every
from
core.models
import
User
,
Token
,
UserLoginSchema
,
DataCenterSchema
from
core.auth
import
signJWT
from
core.bearer
import
get_current_user
,
admin_user
...
...
@@ -95,3 +97,9 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
@app.get
(
"/tokens/"
)
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
return
get_rtokens
(
username
=
username
)
@app.on_event
(
"startup"
)
@repeat_every
(
seconds
=
300
)
def
update_datacenter_healt
():
update_datacenter_status
()
poetry.lock
View file @
69d6fc05
This diff is collapsed.
Click to expand it.
pyproject.toml
View file @
69d6fc05
...
...
@@ -20,6 +20,7 @@ pydantic = {extras = ["email"], version = "^1.10.6"}
passlib
=
"^1.7.4"
black
=
"^23.1.0"
ruff
=
"^0.0.254"
fastapi-utils
=
"^0.2.1"
[tool.poe.tasks.start]
shell
=
"poetry run uvicorn main:app --reload --port 6973 --host 0.0.0.0"
...
...
sredis/sredis.py
View file @
69d6fc05
import
redis
import
requests
from
core.models
import
UserLoginSchema
from
.models
import
PUser
from
passlib.hash
import
pbkdf2_sha256
...
...
@@ -7,6 +8,14 @@ from core.auth import hash_pass
from
fastapi
import
HTTPException
import
random
def
get_status
(
datacenter_url
:
str
):
resp
=
requests
.
request
(
method
=
"GET"
,
url
=
datacenter_url
,
verify
=
False
)
return
int
(
resp
.
status_code
/
100
)
==
2
r
=
redis
.
Redis
(
host
=
"localhost"
,
port
=
6379
,
db
=
0
,
decode_responses
=
True
)
...
...
@@ -24,12 +33,24 @@ def reset():
pipe
.
execute
()
def
update_status
(
datacenter
):
status
=
"OK"
if
get_status
(
datacenter_url
=
datacenter
)
is
True
else
"Wrong"
r
.
hset
(
"datacenter_status"
,
datacenter
,
status
)
def
update_datacenter_status
():
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
for
dc
in
all_keys
.
values
():
update_status
(
datacenter
=
dc
)
def
add_datacenter
(
datacenter
:
str
):
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
r
.
incr
(
"datacenters_cnt"
)
r
.
set
(
"roundrobin_cnt"
,
1
)
r
.
rpush
(
"rrlist"
,
datacenter
)
update_status
(
datacenter
)
def
rr_get
():
...
...
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