-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
55 lines (41 loc) · 1.31 KB
/
__init__.py
File metadata and controls
55 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import asyncio
from fastapi import APIRouter
from lnbits.tasks import create_permanent_unique_task
from loguru import logger
from .crud import db
from .tasks import cleanup_empty_chats, wait_for_paid_invoices
from .views import chat_generic_router, chat_public_router
from .views_api import chat_api_router
from .views_lnurl import chat_lnurl_router
chat_ext: APIRouter = APIRouter(tags=["Chat"])
chat_router: APIRouter = APIRouter(prefix="/chat", tags=["Chat"])
chat_router.include_router(chat_lnurl_router)
chat_router.include_router(chat_api_router)
chat_router.include_router(chat_generic_router)
chat_ext.include_router(chat_router)
chat_ext.include_router(chat_public_router)
chat_static_files = [
{
"path": "/chat/static",
"name": "chat_static",
}
]
scheduled_tasks: list[asyncio.Task] = []
def chat_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)
def chat_start():
task = create_permanent_unique_task("ext_chat", wait_for_paid_invoices)
scheduled_tasks.append(task)
cleanup_task = create_permanent_unique_task("ext_chat_cleanup", cleanup_empty_chats)
scheduled_tasks.append(cleanup_task)
__all__ = [
"chat_ext",
"chat_start",
"chat_static_files",
"chat_stop",
"db",
]