Work on websockets. Finally 97.25% working?
This commit is contained in:
@@ -764,89 +764,3 @@ async def redis_connector(
|
||||
task.cancel()
|
||||
await redis.close()
|
||||
# await redis.wait_closed()
|
||||
|
||||
|
||||
|
||||
#### ####
|
||||
|
||||
# @app.on_event('shutdown')
|
||||
# async def shutdown():
|
||||
# log.info('The Aether FastAPI API is shutting down...')
|
||||
# # await ws_conn.close()
|
||||
# await redis_conn.close()
|
||||
|
||||
# pending_tasks = asyncio.all_tasks(loop=event_loop)
|
||||
|
||||
# # cancel each pending task
|
||||
# for task in pending_tasks:
|
||||
# logger.info(f'killing task {task.get_coro()}')
|
||||
# event_loop.call_soon_threadsafe(task.cancel)
|
||||
|
||||
# # This does not work for some reason.
|
||||
# # "Passing coroutines is forbidden, use tasks explicitly."
|
||||
# log.info('Start asyncio wait')
|
||||
# done, pending = await asyncio.wait(
|
||||
# [receiver_task, producer_task],
|
||||
# return_when = asyncio.FIRST_COMPLETED,
|
||||
# )
|
||||
# log.debug(f'Done task: {done}')
|
||||
|
||||
# for task in pending:
|
||||
# log.debug(f'Canceling task: {task}')
|
||||
# task.cancel()
|
||||
# await redis_conn.close()
|
||||
# await redis_conn.wait_closed()
|
||||
|
||||
|
||||
|
||||
# (channel,) = await r.subscribe('chat:c')
|
||||
# assert isinstance(channel, redis.Channel)
|
||||
# try:
|
||||
# while True:
|
||||
# data = await channel.get()
|
||||
# if data:
|
||||
# await ws_conn.send_json(data)
|
||||
# except Exception as exc:
|
||||
# # TODO this needs handling better
|
||||
# log.error(exc)
|
||||
|
||||
# receiver_task = receiver_handler(ws_conn, redis_conn, client_id, group_id)
|
||||
|
||||
# future_receiver = asyncio.create_task(receiver_task())
|
||||
|
||||
# sender_task = sender_handler(redis_conn_pubsub, ws_conn, client_id, group_id)
|
||||
|
||||
# future_sender = asyncio.create_task(sender_task())
|
||||
|
||||
|
||||
# async def reader(channel: redis.client.PubSub):
|
||||
# while True:
|
||||
# message = await channel.get_message(ignore_subscribe_messages=True)
|
||||
# if message is not None:
|
||||
# log.debug(f'(Reader) Message Received: {message}')
|
||||
# log.info('WHAT NOW???')
|
||||
# if message['data'].decode() == STOPWORD:
|
||||
# log.debug('(Reader) STOP')
|
||||
# break
|
||||
|
||||
# r = redis.from_url('redis://localhost')
|
||||
# r = redis.Redis(host=settings.REDIS['server'], port=settings.REDIS['port'], db=6, password=None, encoding='utf-8', decode_responses=True)
|
||||
# async with r.pubsub() as pubsub:
|
||||
# await pubsub.subscribe('channel:1', 'channel:2', 'chat:c')
|
||||
|
||||
# future = asyncio.create_task(reader(pubsub))
|
||||
|
||||
# await r.publish('channel:1', 'Hello')
|
||||
# await r.publish('channel:2', 'World')
|
||||
# await r.publish('channel:1', STOPWORD)
|
||||
|
||||
# await future
|
||||
|
||||
# @app.on_event('shutdown')
|
||||
# async def shutdown():
|
||||
# log.setLevel(logging.INFO) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
|
||||
# log.info('The Aether FastAPI API is shutting down...')
|
||||
# #await database.disconnect()
|
||||
# r.close()
|
||||
Reference in New Issue
Block a user