Skip to content

Commit

Permalink
fix: properly start/stop tasks (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
dni authored Apr 15, 2024
1 parent 662587d commit b985304
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -28,6 +29,15 @@ def events_renderer():
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)

0 comments on commit b985304

Please sign in to comment.