import asyncio

import uvicorn
from fastapi import FastAPI

from src.controllers.oxk_controller import oxk_router
from src.lib import augur_config, logger
from src.lib.utils import create_augur_ascii_art


@logger.catch()
async def main():
    logger.info(f"\n{create_augur_ascii_art()}")
    logger.info("Инициализация клиента FastAPI и роутингов")
    app_client = FastAPI(
        title='AugurAPI',
        description='API для системы ботов Augur',
        version='0.0.1',
        docs_url='/docs',
        redoc_url='/redoc',
        )

    app_client.include_router(oxk_router)
    logger.info("Завершение инициализации клиента FastAPI и роутингов")

    logger.info(f"Запуск uvicorn сервера на {augur_config['host']}:{augur_config['port']}")
    uvicorn.run(app_client, host=augur_config['host'], port=augur_config['port'])


if __name__ == '__main__':
    asyncio.run(main())





2024-05-29 19:33:20.098 | ERROR    | asyncio.events:_run:80 - An error has been caught in function '_run', process 'MainProcess' (4960), thread 'MainThread' (15800):
Traceback (most recent call last):

  File "D:\Augur\src\AugurAPI\main.py", line 31, in <module>
    asyncio.run(main())
    │       │   └ <function main at 0x00000191BB58AF20>
    │       └ <function run at 0x00000191B8C6F060>
    └ <module 'asyncio' from 'C:\\Python311\\Lib\\asyncio\\__init__.py'>

  File "C:\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           │      │   └ <coroutine object main at 0x00000191BB502C40>
           │      └ <function Runner.run at 0x00000191B8C73240>
           └ <asyncio.runners.Runner object at 0x00000191B6FC9B50>
  File "C:\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           │    │     │                  └ <Task pending name='Task-1' coro=<main() running at D:\Augur\src\AugurAPI\venv\Lib\site-packages\loguru\_logger.py:1262> cb=[...
           │    │     └ <function BaseEventLoop.run_until_complete at 0x00000191B8C70EA0>
           │    └ <ProactorEventLoop running=True closed=False debug=False>
           └ <asyncio.runners.Runner object at 0x00000191B6FC9B50>
  File "C:\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
    self.run_forever()
    │    └ <function ProactorEventLoop.run_forever at 0x00000191B8D3C040>
    └ <ProactorEventLoop running=True closed=False debug=False>
  File "C:\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x00000191B8C72C00>
    └ <ProactorEventLoop running=True closed=False debug=False>
  File "C:\Python311\Lib\asyncio\base_events.py", line 1922, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x00000191B8BB9260>
    └ <Handle <TaskStepMethWrapper object at 0x00000191BB9E21D0>()>
> File "C:\Python311\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle <TaskStepMethWrapper object at 0x00000191BB9E21D0>()>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle <TaskStepMethWrapper object at 0x00000191BB9E21D0>()>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle <TaskStepMethWrapper object at 0x00000191BB9E21D0>()>

  File "D:\Augur\src\AugurAPI\main.py", line 27, in main
    uvicorn.run(app_client, host=augur_config['host'], port=augur_config['port'])
    │       │   │                │                          └ {'host': '127.0.0.1', 'port': 5000, 'log_path': '..\\Logs\\AugurAPI\\log.txt', 'log_level': 'DEBUG'}
    │       │   │                └ {'host': '127.0.0.1', 'port': 5000, 'log_path': '..\\Logs\\AugurAPI\\log.txt', 'log_level': 'DEBUG'}
    │       │   └ <fastapi.applications.FastAPI object at 0x00000191BBA066D0>
    │       └ <function run at 0x00000191B93C14E0>
    └ <module 'uvicorn' from 'D:\\Augur\\src\\AugurAPI\\venv\\Lib\\site-packages\\uvicorn\\__init__.py'>

  File "D:\Augur\src\AugurAPI\venv\Lib\site-packages\uvicorn\main.py", line 575, in run
    server.run()
    │      └ <function Server.run at 0x00000191B941CAE0>
    └ <uvicorn.server.Server object at 0x00000191BB6C4610>
  File "D:\Augur\src\AugurAPI\venv\Lib\site-packages\uvicorn\server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           │       │   │    │             └ None
           │       │   │    └ <function Server.serve at 0x00000191B941CB80>
           │       │   └ <uvicorn.server.Server object at 0x00000191BB6C4610>
           │       └ <function run at 0x00000191B8C6F060>
           └ <module 'asyncio' from 'C:\\Python311\\Lib\\asyncio\\__init__.py'>
  File "C:\Python311\Lib\asyncio\runners.py", line 186, in run
    raise RuntimeError(

RuntimeError: asyncio.run() cannot be called from a running event loop
D:\Augur\src\AugurAPI\venv\Lib\site-packages\loguru\_logger.py:1262: RuntimeWarning: coroutine 'Server.serve' was never awaited
  with catcher:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Process finished with exit code 0