mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-19 12:37:30 +02:00
refactor: move some config vars to the .env file
This commit is contained in:
parent
bba02d03e3
commit
c33351d968
5 changed files with 22 additions and 7 deletions
|
|
@ -1,5 +1,17 @@
|
|||
secret=please_please_update_me_please
|
||||
algorithm=HS256
|
||||
# expiry time in seconds
|
||||
jwt_expiry_time=300
|
||||
|
||||
# Amount of seconds the app will wait until it'll
|
||||
# send another hardware update
|
||||
gather_hw_info_interval = 2
|
||||
# Amount of seconds the app will gather CPU usage data for each update
|
||||
# The resulting CPU usage is averaged over this period of time.
|
||||
# To get realistic results at least 0.1 seconds is recommended
|
||||
# must be less than and not equal to gather_hw_info_interval
|
||||
cpu_usage_averaging_period = 0.5
|
||||
|
||||
|
||||
# Redis - uncomment if Redis runs with non standard values (i.e. in Docker etc)
|
||||
# redis_host=127.0.0.1
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
__pycache__
|
||||
.env
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Configuration
|
||||
|
||||
Update the `.env` file with your `bitcoind` and `lnd` configuration.
|
||||
Create a `.env` file with your `bitcoind` and `lnd` configuration. See the `.env_sample` file for all configuration options.
|
||||
|
||||
Please note that you will also need to install [Redis](https://redis.io/).
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ from decouple import config
|
|||
|
||||
JWT_SECRET = config("secret")
|
||||
JWT_ALGORITHM = config("algorithm")
|
||||
JWT_EXPIRY_TIME = config("jwt_expiry_time", default=300.0, cast=float)
|
||||
|
||||
|
||||
def signJWT() -> Dict[str, str]:
|
||||
payload = {"user_id": "admin", "expires": time.time() + 300}
|
||||
payload = {"user_id": "admin", "expires": time.time() + JWT_EXPIRY_TIME}
|
||||
token = jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)
|
||||
return token_response(token)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@ import asyncio
|
|||
|
||||
import psutil
|
||||
from app.utils import SSE, send_sse_message
|
||||
from decouple import config
|
||||
from fastapi import Request
|
||||
|
||||
SLEEP_TIME = 1
|
||||
CPU_USAGE_INTERVAL = 0.5
|
||||
HW_INFO_YIELD_TIME = SLEEP_TIME+CPU_USAGE_INTERVAL
|
||||
SLEEP_TIME = config("gather_hw_info_interval", default=2, cast=float)
|
||||
CPU_AVG_PERIOD = config("cpu_usage_averaging_period", default=0.5, cast=float)
|
||||
HW_INFO_YIELD_TIME = SLEEP_TIME+CPU_AVG_PERIOD
|
||||
|
||||
|
||||
async def subscribe_hardware_info(request: Request):
|
||||
|
|
@ -22,9 +23,9 @@ def get_hardware_info() -> map:
|
|||
info = {}
|
||||
|
||||
info['cpu_overall_percent'] = psutil.cpu_percent(
|
||||
interval=CPU_USAGE_INTERVAL)
|
||||
interval=CPU_AVG_PERIOD)
|
||||
info['cpu_per_cpu_percent'] = psutil.cpu_percent(
|
||||
interval=CPU_USAGE_INTERVAL, percpu=True)
|
||||
interval=CPU_AVG_PERIOD, percpu=True)
|
||||
|
||||
v = psutil.virtual_memory()
|
||||
info['vram_total_bytes'] = v.total
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue