Load nodes from cache

tempfix
tobtoht 3 years ago
parent f4aa1227ea
commit ce40243de4

@ -17,16 +17,16 @@ import settings
now = datetime.now()
app: Quart = None
cache = None
rpc_nodes: dict = None
user_agents: List[str] = None
connected_websockets: Set[asyncio.Queue] = set()
_is_primary_worker_thread = False
async def _setup_nodes(app: Quart):
global rpc_nodes
with open("data/nodes.json", "r") as f:
rpc_nodes = json.loads(f.read()).get(settings.COIN_SYMBOL)
global cache
with open('data/nodes.json', 'r') as f:
nodes = json.loads(f.read()).get(settings.COIN_SYMBOL)
cache.execute('JSON.SET', 'nodes', '.', json.dumps(nodes))
async def _setup_user_agents(app: Quart):

@ -123,6 +123,16 @@ class FeatherTask:
async def end(self, result: dict):
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:
from fapi.factory import app, cache

@ -24,13 +24,15 @@ class RPCNodeCheckTask(FeatherTask):
async def task(self) -> List[dict]:
"""Check RPC nodes status"""
from fapi.factory import app, rpc_nodes, cache
from fapi.factory import app, cache
try:
heights = json.loads(await cache.get("blockheights"))
except:
heights = {}
rpc_nodes = await self.cache_json_get("nodes")
nodes = []
for network_type_coin, _ in rpc_nodes.items():
data = []

Loading…
Cancel
Save