mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-01 02:12:30 +00:00
blackified code
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
9fc3e597a5
commit
358a4ff027
@ -7,6 +7,7 @@ from planetmint.ipc.events import EventTypes, POISON_PILL
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Exchange:
|
class Exchange:
|
||||||
"""Dispatch events to subscribers."""
|
"""Dispatch events to subscribers."""
|
||||||
|
|
||||||
@ -76,4 +77,3 @@ class Exchange:
|
|||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Exchange Exception: {e}")
|
logger.debug(f"Exchange Exception: {e}")
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ class TransactionListApi(Resource):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Tendermint RPC connection issue: {e}")
|
logger.error(f"Tendermint RPC connection issue: {e}")
|
||||||
status_code = 500
|
status_code = 500
|
||||||
message = { "detail": "Tendermint RPC connection error"}
|
message = {"detail": "Tendermint RPC connection error"}
|
||||||
|
|
||||||
if status_code == 202:
|
if status_code == 202:
|
||||||
response = jsonify(tx)
|
response = jsonify(tx)
|
||||||
|
@ -58,14 +58,14 @@ class Dispatcher:
|
|||||||
return {"height": block["height"], "hash": block["hash"], "transaction_ids": txids}
|
return {"height": block["height"], "hash": block["hash"], "transaction_ids": txids}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_queue_on_demand(app, queue_name:str):
|
def get_queue_on_demand(app, queue_name: str):
|
||||||
if queue_name not in app:
|
if queue_name not in app:
|
||||||
logging.debug(f"creating queue: {queue_name}")
|
logging.debug(f"creating queue: {queue_name}")
|
||||||
get_loop = asyncio.get_event_loop()
|
get_loop = asyncio.get_event_loop()
|
||||||
run_loop = asyncio.get_running_loop()
|
run_loop = asyncio.get_running_loop()
|
||||||
logging.debug(f"get loop: {get_loop}")
|
logging.debug(f"get loop: {get_loop}")
|
||||||
logging.debug(f"run loop: {run_loop}")
|
logging.debug(f"run loop: {run_loop}")
|
||||||
app[queue_name] = asyncio.Queue( loop=get_loop)
|
app[queue_name] = asyncio.Queue(loop=get_loop)
|
||||||
|
|
||||||
return app[queue_name]
|
return app[queue_name]
|
||||||
|
|
||||||
@ -87,9 +87,9 @@ class Dispatcher:
|
|||||||
logger.debug(f"DISPATCHER CALLED : {self.type}")
|
logger.debug(f"DISPATCHER CALLED : {self.type}")
|
||||||
while True:
|
while True:
|
||||||
if self.type == "tx":
|
if self.type == "tx":
|
||||||
event = await Dispatcher.get_queue_on_demand( app, "tx_source").get()
|
event = await Dispatcher.get_queue_on_demand(app, "tx_source").get()
|
||||||
elif self.type == "blk":
|
elif self.type == "blk":
|
||||||
event = await Dispatcher.get_queue_on_demand( app, "blk_source").get()
|
event = await Dispatcher.get_queue_on_demand(app, "blk_source").get()
|
||||||
str_buffer = []
|
str_buffer = []
|
||||||
|
|
||||||
if event == POISON_PILL:
|
if event == POISON_PILL:
|
||||||
|
@ -32,8 +32,8 @@ EVENTS_ENDPOINT_BLOCKS = "/api/v1/streams/valid_blocks"
|
|||||||
|
|
||||||
async def access_queue(app):
|
async def access_queue(app):
|
||||||
in_queue = app["event_source"]
|
in_queue = app["event_source"]
|
||||||
tx_source = Dispatcher.get_queue_on_demand(app,"tx_source" )
|
tx_source = Dispatcher.get_queue_on_demand(app, "tx_source")
|
||||||
blk_source = Dispatcher.get_queue_on_demand(app,"blk_source" )
|
blk_source = Dispatcher.get_queue_on_demand(app, "blk_source")
|
||||||
logger.debug(f"REROUTING CALLED")
|
logger.debug(f"REROUTING CALLED")
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@ -47,11 +47,12 @@ async def access_queue(app):
|
|||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"REROUTING wait exception : {e}")
|
logger.debug(f"REROUTING wait exception : {e}")
|
||||||
raise e #await asyncio.sleep(1)
|
raise e # await asyncio.sleep(1)
|
||||||
except asyncio.CancelledError as e:
|
except asyncio.CancelledError as e:
|
||||||
logger.debug(f"REROUTING Cancelled : {e}")
|
logger.debug(f"REROUTING Cancelled : {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def websocket_tx_handler(request):
|
async def websocket_tx_handler(request):
|
||||||
"""Handle a new socket connection."""
|
"""Handle a new socket connection."""
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ def init_app(sync_event_source):
|
|||||||
app = aiohttp.web.Application()
|
app = aiohttp.web.Application()
|
||||||
app["event_source"] = sync_event_source
|
app["event_source"] = sync_event_source
|
||||||
|
|
||||||
#dispatchers
|
# dispatchers
|
||||||
app["tx_dispatcher"] = Dispatcher("tx")
|
app["tx_dispatcher"] = Dispatcher("tx")
|
||||||
app["blk_dispatcher"] = Dispatcher("blk")
|
app["blk_dispatcher"] = Dispatcher("blk")
|
||||||
|
|
||||||
@ -137,9 +138,10 @@ def init_app(sync_event_source):
|
|||||||
app.router.add_get(EVENTS_ENDPOINT, websocket_tx_handler)
|
app.router.add_get(EVENTS_ENDPOINT, websocket_tx_handler)
|
||||||
app.router.add_get(EVENTS_ENDPOINT_BLOCKS, websocket_blk_handler)
|
app.router.add_get(EVENTS_ENDPOINT_BLOCKS, websocket_blk_handler)
|
||||||
|
|
||||||
app.on_startup.append( start_background_tasks )
|
app.on_startup.append(start_background_tasks)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def start(sync_event_source):
|
def start(sync_event_source):
|
||||||
app = init_app(sync_event_source)
|
app = init_app(sync_event_source)
|
||||||
aiohttp.web.run_app(app, host=Config().get()["wsserver"]["host"], port=Config().get()["wsserver"]["port"])
|
aiohttp.web.run_app(app, host=Config().get()["wsserver"]["host"], port=Config().get()["wsserver"]["port"])
|
Loading…
x
Reference in New Issue
Block a user