Simone Robutti 44340fde8f
Introduced FastAPI and Postgres support (#173)
* added poc

* added check for sqlite db

* added events test

* draft docker-compose-test.yml

* improved docker-compose

* added support for postgres migrations

* add documentation

* added some qol to migrations

* added migration generation script

* removed settings.toml

* waiting for postgress in script

* commented script

* added sample web config

* fixed tests

* mock memory db

* reviewed PR
2022-10-14 22:11:27 +02:00

37 lines
786 B
Python

import asyncio
import functools
import logging
import sys
import traceback
from mobilizon_reshare.config.command import CommandConfig
from mobilizon_reshare.storage.db import tear_down, init
logger = logging.getLogger(__name__)
async def graceful_exit():
await tear_down()
async def _safe_execution(function):
await init()
return_code = 1
try:
return_code = await function()
except Exception:
traceback.print_exc()
finally:
logger.debug("Closing")
await graceful_exit()
return return_code
def safe_execution(function, command_config: CommandConfig = None):
if command_config:
function = functools.partial(function, command_config)
code = asyncio.run(_safe_execution(function))
sys.exit(code)