mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
Load nodes from cache
This commit is contained in:
parent
f4aa1227ea
commit
ce40243de4
3 changed files with 17 additions and 5 deletions
|
@ -17,16 +17,16 @@ import settings
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
app: Quart = None
|
app: Quart = None
|
||||||
cache = None
|
cache = None
|
||||||
rpc_nodes: dict = None
|
|
||||||
user_agents: List[str] = None
|
user_agents: List[str] = None
|
||||||
connected_websockets: Set[asyncio.Queue] = set()
|
connected_websockets: Set[asyncio.Queue] = set()
|
||||||
_is_primary_worker_thread = False
|
_is_primary_worker_thread = False
|
||||||
|
|
||||||
|
|
||||||
async def _setup_nodes(app: Quart):
|
async def _setup_nodes(app: Quart):
|
||||||
global rpc_nodes
|
global cache
|
||||||
with open("data/nodes.json", "r") as f:
|
with open('data/nodes.json', 'r') as f:
|
||||||
rpc_nodes = json.loads(f.read()).get(settings.COIN_SYMBOL)
|
nodes = json.loads(f.read()).get(settings.COIN_SYMBOL)
|
||||||
|
cache.execute('JSON.SET', 'nodes', '.', json.dumps(nodes))
|
||||||
|
|
||||||
|
|
||||||
async def _setup_user_agents(app: Quart):
|
async def _setup_user_agents(app: Quart):
|
||||||
|
|
|
@ -123,6 +123,16 @@ class FeatherTask:
|
||||||
async def end(self, result: dict):
|
async def end(self, result: dict):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
async def cache_json_get(self, key: str, path="."):
|
||||||
|
from fapi.factory import app, cache
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = await cache.execute('JSON.GET', key, path)
|
||||||
|
if data:
|
||||||
|
return json.loads(data)
|
||||||
|
except Exception as ex:
|
||||||
|
app.logger.error(f"Redis error: {ex}")
|
||||||
|
|
||||||
async def cache_get(self, key: str) -> dict:
|
async def cache_get(self, key: str) -> dict:
|
||||||
from fapi.factory import app, cache
|
from fapi.factory import app, cache
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,15 @@ class RPCNodeCheckTask(FeatherTask):
|
||||||
|
|
||||||
async def task(self) -> List[dict]:
|
async def task(self) -> List[dict]:
|
||||||
"""Check RPC nodes status"""
|
"""Check RPC nodes status"""
|
||||||
from fapi.factory import app, rpc_nodes, cache
|
from fapi.factory import app, cache
|
||||||
|
|
||||||
try:
|
try:
|
||||||
heights = json.loads(await cache.get("blockheights"))
|
heights = json.loads(await cache.get("blockheights"))
|
||||||
except:
|
except:
|
||||||
heights = {}
|
heights = {}
|
||||||
|
|
||||||
|
rpc_nodes = await self.cache_json_get("nodes")
|
||||||
|
|
||||||
nodes = []
|
nodes = []
|
||||||
for network_type_coin, _ in rpc_nodes.items():
|
for network_type_coin, _ in rpc_nodes.items():
|
||||||
data = []
|
data = []
|
||||||
|
|
Loading…
Reference in a new issue