fix: properly start/stop tasks (#18)
https://github.com/lnbits/lnbits/issues/2411
This commit is contained in:
parent
82d4c65d1e
commit
dbeb3d9050
2 changed files with 14 additions and 21 deletions
18
__init__.py
18
__init__.py
|
|
@ -1,16 +1,14 @@
|
|||
import asyncio
|
||||
from typing import List
|
||||
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_splitpayments")
|
||||
|
||||
scheduled_tasks: List[asyncio.Task] = []
|
||||
|
||||
splitpayments_static_files = [
|
||||
{
|
||||
"path": "/splitpayments/static",
|
||||
|
|
@ -31,7 +29,15 @@ from .views import * # noqa: F401,F403
|
|||
from .views_api import * # noqa: F401,F403
|
||||
|
||||
|
||||
scheduled_tasks: list[asyncio.Task] = []
|
||||
|
||||
def splitpayments_stop():
|
||||
for task in scheduled_tasks:
|
||||
try:
|
||||
task.cancel()
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
|
||||
def splitpayments_start():
|
||||
loop = asyncio.get_event_loop()
|
||||
task = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||
task = create_permanent_unique_task("ext_splitpayments", wait_for_paid_invoices)
|
||||
scheduled_tasks.append(task)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue