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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
0 deletions
+30
-0
balancer/util.py
+0
-0
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
main.py
View file @
69d6fc05
...
@@ -10,9 +10,11 @@ from sredis.sredis import (
...
@@ -10,9 +10,11 @@ from sredis.sredis import (
create_superpuser
,
create_superpuser
,
get_rtokens
,
get_rtokens
,
reset
,
reset
,
update_datacenter_status
,
)
)
import
logging
import
logging
import
requests
import
requests
from
fastapi_utils.tasks
import
repeat_every
from
core.models
import
User
,
Token
,
UserLoginSchema
,
DataCenterSchema
from
core.models
import
User
,
Token
,
UserLoginSchema
,
DataCenterSchema
from
core.auth
import
signJWT
from
core.auth
import
signJWT
from
core.bearer
import
get_current_user
,
admin_user
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)):
...
@@ -95,3 +97,9 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
@app.get
(
"/tokens/"
)
@app.get
(
"/tokens/"
)
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
return
get_rtokens
(
username
=
username
)
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"}
...
@@ -20,6 +20,7 @@ pydantic = {extras = ["email"], version = "^1.10.6"}
passlib
=
"^1.7.4"
passlib
=
"^1.7.4"
black
=
"^23.1.0"
black
=
"^23.1.0"
ruff
=
"^0.0.254"
ruff
=
"^0.0.254"
fastapi-utils
=
"^0.2.1"
[tool.poe.tasks.start]
[tool.poe.tasks.start]
shell
=
"poetry run uvicorn main:app --reload --port 6973 --host 0.0.0.0"
shell
=
"poetry run uvicorn main:app --reload --port 6973 --host 0.0.0.0"
...
...
sredis/sredis.py
View file @
69d6fc05
import
redis
import
redis
import
requests
from
core.models
import
UserLoginSchema
from
core.models
import
UserLoginSchema
from
.models
import
PUser
from
.models
import
PUser
from
passlib.hash
import
pbkdf2_sha256
from
passlib.hash
import
pbkdf2_sha256
...
@@ -7,6 +8,14 @@ from core.auth import hash_pass
...
@@ -7,6 +8,14 @@ from core.auth import hash_pass
from
fastapi
import
HTTPException
from
fastapi
import
HTTPException
import
random
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
)
r
=
redis
.
Redis
(
host
=
"localhost"
,
port
=
6379
,
db
=
0
,
decode_responses
=
True
)
...
@@ -24,12 +33,24 @@ def reset():
...
@@ -24,12 +33,24 @@ def reset():
pipe
.
execute
()
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
):
def
add_datacenter
(
datacenter
:
str
):
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
r
.
incr
(
"datacenters_cnt"
)
r
.
incr
(
"datacenters_cnt"
)
r
.
set
(
"roundrobin_cnt"
,
1
)
r
.
set
(
"roundrobin_cnt"
,
1
)
r
.
rpush
(
"rrlist"
,
datacenter
)
r
.
rpush
(
"rrlist"
,
datacenter
)
update_status
(
datacenter
)
def
rr_get
():
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