fix: properly start/stop tasks (#27)

https://github.com/lnbits/lnbits/issues/2411
This commit is contained in:
dni ⚡ 2024-04-15 12:53:16 +02:00 committed by GitHub
parent 662587dbf2
commit b985304384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,11 @@
import asyncio
from loguru import logger
from fastapi import APIRouter
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_events")
@ -28,6 +29,15 @@ from .views import * # noqa: F401,F403
from .views_api import * # noqa: F401,F403
scheduled_tasks: list[asyncio.Task] = []
def events_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)
def events_start():
loop = asyncio.get_event_loop()
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
task = create_permanent_unique_task("ext_events", wait_for_paid_invoices)
scheduled_tasks.append(task)