Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop scheduled tasks #70

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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_task
from typing import Callable
from fastapi.responses import JSONResponse

Expand Down Expand Up @@ -55,6 +55,15 @@ def tpos_renderer():
from .views_api import * # noqa


scheduled_tasks: list[asyncio.Task] = []

def tpos_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)

def tpos_start():
loop = asyncio.get_event_loop()
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
task = create_permanent_task(wait_for_paid_invoices)
scheduled_tasks.append(task)