Skip to content

Commit 9585f2a

Browse files
authoredApr 15, 2024
fix: properly start/stop tasks (#8)
lnbits/lnbits#2411
1 parent 41fbd84 commit 9585f2a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
 

‎__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import asyncio
22

33
from fastapi import APIRouter
4+
from loguru import logger
45

56
from lnbits.db import Database
67
from lnbits.helpers import template_renderer
7-
from lnbits.tasks import catch_everything_and_restart
8+
from lnbits.tasks import create_permanent_unique_task
89

910
db = Database("ext_example")
1011

@@ -27,6 +28,15 @@ def example_renderer():
2728
from .views_api import * # noqa: F401,F403
2829

2930

31+
scheduled_tasks: list[asyncio.Task] = []
32+
33+
def example_stop():
34+
for task in scheduled_tasks:
35+
try:
36+
task.cancel()
37+
except Exception as ex:
38+
logger.warning(ex)
39+
3040
def example_start():
31-
loop = asyncio.get_event_loop()
32-
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
41+
task = create_permanent_unique_task("ext_example", wait_for_paid_invoices)
42+
scheduled_tasks.append(task)

0 commit comments

Comments
 (0)