async def database_backup_routine(app): try: while True: await asyncio.sleep(app['config']['BACKUP_INT']) with obtain_connection(app['db_path']) as conn: logger.debug('backing up database') schema.db_helpers.backup_database(conn, app['backup']) except asyncio.CancelledError: pass
async def start_background_tasks(app: web.Application): app['reader'] = obtain_connection(app['db_path'], True) app['waitful_backup'] = app.loop.create_task(database_backup_routine(app)) app['comment_scheduler'] = await create_comment_scheduler() app['writer'] = DatabaseWriter(app['db_path'])
def handle_get_comments_by_id(app, **kwargs): with obtain_connection(app['db_path']) as conn: return get_comments_by_id(conn, **kwargs)
def setUp(self) -> None: super().setUp() if pathlib.Path(config['PATH']['TEST']).exists(): teardown_database(config['PATH']['TEST']) setup_database(config['PATH']['TEST']) self.conn = obtain_connection(config['PATH']['TEST'])