diff --git a/__init__.py b/__init__.py index 72ee546..3376c8f 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,11 @@ import asyncio from fastapi import APIRouter +from loguru import logger from lnbits.db import Database from lnbits.helpers import template_renderer -from lnbits.tasks import catch_everything_and_restart +from lnbits.tasks import create_permanent_unique_task db = Database("ext_livestream") @@ -28,6 +29,15 @@ def livestream_renderer(): from .views_api import * # noqa: F401,F403 +scheduled_tasks: list[asyncio.Task] = [] + +def livestream_stop(): + for task in scheduled_tasks: + try: + task.cancel() + except Exception as ex: + logger.warning(ex) + def livestream_start(): - loop = asyncio.get_event_loop() - loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) + task = create_permanent_unique_task("ext_livestream", wait_for_paid_invoices) + scheduled_tasks.append(task)