Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix stop tasks pr from vlad
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Feb 17, 2023
1 parent e6426e3 commit bacd448
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fastapi import APIRouter
from starlette.staticfiles import StaticFiles
from typing import List

from lnbits.db import Database
from lnbits.helpers import template_renderer
Expand Down Expand Up @@ -37,7 +38,9 @@ def market_renderer():
from .views import * # noqa: F401,F403
from .views_api import * # noqa: F401,F403

scheduled_tasks: List[asyncio.Task] = []

def market_start():
loop = asyncio.get_event_loop()
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
task = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
scheduled_tasks.append(task)
14 changes: 13 additions & 1 deletion views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
get_key_type,
require_admin_key,
require_invoice_key,
check_admin,
)
from lnbits.helpers import urlsafe_short_hash
from lnbits.utils.exchange_rates import currencies

from . import db, market_ext
from . import db, market_ext, scheduled_tasks
from .crud import (
create_market_market,
create_market_market_stalls,
Expand Down Expand Up @@ -525,3 +526,14 @@ async def api_set_settings(
user = wallet.wallet.user

return await create_market_settings(user, data)


@market_ext.delete("/api/v1", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)])
async def api_stop():
for t in scheduled_tasks:
try:
t.cancel()
except Exception as ex:
logger.warning(ex)

return {"success": True}

0 comments on commit bacd448

Please sign in to comment.