nostrmarket/__init__.py
Tiago Vasconcelos 3aa34bc5bf allow custom path (#83)
* allow custom path

* fix: update min_lnbits_version to 0.11.0

---------

Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
2023-09-26 15:30:49 +03:00

55 lines
1.5 KiB
Python

import asyncio
from asyncio import Task
from typing import List
from fastapi import APIRouter
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
db = Database("ext_nostrmarket")
nostrmarket_ext: APIRouter = APIRouter(prefix="/nostrmarket", tags=["nostrmarket"])
nostrmarket_static_files = [
{
"path": "/nostrmarket/static",
"name": "nostrmarket_static",
}
]
def nostrmarket_renderer():
return template_renderer(["nostrmarket/templates"])
from .nostr.nostr_client import NostrClient
nostr_client = NostrClient()
scheduled_tasks: List[Task] = []
from .tasks import wait_for_nostr_events, wait_for_paid_invoices
from .views import * # noqa
from .views_api import * # noqa
def nostrmarket_start():
async def _subscribe_to_nostr_client():
# wait for 'nostrclient' extension to initialize
await asyncio.sleep(10)
await nostr_client.run_forever()
raise ValueError("Must reconnect to websocket")
async def _wait_for_nostr_events():
# wait for this extension to initialize
await asyncio.sleep(15)
await wait_for_nostr_events(nostr_client)
loop = asyncio.get_event_loop()
task1 = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
task2 = loop.create_task(catch_everything_and_restart(_subscribe_to_nostr_client))
task3 = loop.create_task(catch_everything_and_restart(_wait_for_nostr_events))
scheduled_tasks.extend([task1, task2, task3])