Spaces:
Runtime error
Runtime error
File size: 731 Bytes
f78e6de |
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 |
# PATH: bot/core/tasks.py
from dataclasses import dataclass
from typing import Optional
import time
@dataclass
class Task:
id: str
uid: int
status: str = "queued"
detail: str = ""
created_at: float = time.time()
yt_url: Optional[str] = None
_TASKS: dict[str, Task] = {}
def create_task(task_id: str, uid: int) -> Task:
t = Task(id=task_id, uid=uid)
_TASKS[task_id] = t
return t
def get_task(task_id: str) -> Optional[Task]:
return _TASKS.get(task_id)
def set_task(task_id: str, status: str, detail: str = "", yt_url: str | None = None) -> None:
t = _TASKS.get(task_id)
if not t:
return
t.status = status
t.detail = detail
if yt_url:
t.yt_url = yt_url |