Status system reworked

This commit is contained in:
alejo committed 2026-10-29 01:02:06 -03:00
1 parent 33567db5a3
commit a29ba6e4d2
18 files changed
+326 -345

No files matched your search

+9 -9
View File
@@ -54,7 +54,6 @@ class Level(IntEnum):
class WaitState(IntEnum):
NONE = 0
WAITING = 1
LIMIT_RESET = 2
# ---- Errors ------------------------------------------------------------------------
@@ -92,13 +91,13 @@ _ERRORS = {E_INVALID: InvalidArgument, E_NOT_FOUND: NotFound, E_EXISTS: AlreadyE
class Task:
name: str
account: Optional[str]
status: Status # as shown: Wait / Limit reset come from the account
status_label: str # "Prompt", "Limit reset", "Wait 16:30", ...
status: Status # as shown (Wait becomes Limit reset when the account's wait ends)
status_label: str # "Prompt", "Limit reset", "Wait 16:30", "Testing (account-waiting)"...
stored_status: Status # what is saved underneath
until: Optional[datetime] # for Wait / Limit reset: when the wait ends (ended)
notes: str
notes_lines: int
overrides_wait: bool # its account waits, but this task (set to Testing / Prompt) ignores it
account_waiting: bool # Prompt / Testing while its account waits (the label says so)
@dataclass(frozen=True)
@@ -108,7 +107,7 @@ class Account:
level_label: str # "Busy", "Taken", "Free"
wait_state: WaitState
wait_until: Optional[datetime]
wait_listed: bool # the wait is not shown by any task (account is still Busy)
wait_listed: bool # waiting, but no task is set to Wait (the account is still Busy)
tasks: Tuple[str, ...] # tasks at the account's level
@@ -124,7 +123,7 @@ class _TaskInfo(ctypes.Structure):
("until", ctypes.c_int64),
("notes", ctypes.c_char_p),
("notes_lines", ctypes.c_int),
("overrides_wait", ctypes.c_int),
("account_waiting", ctypes.c_int),
]
@@ -348,14 +347,15 @@ class Database:
def set_account_wait(self, name: str, until: Union[str, datetime, int, float]) -> None:
"""The account hit its limit until `until`: a clock time such as "16:30" / "4:30pm"
(a time that has passed today means tomorrow), a datetime, or Unix seconds."""
(a time that has passed today means tomorrow), a datetime, or Unix seconds. Tasks
set to "wait" follow it; when the time passes they become Limit reset."""
if isinstance(until, str):
self._call("lls_account_set_wait", _enc(name), _enc(until))
else:
self._call("lls_account_set_wait_at", _enc(name), _seconds(until))
def clear_account_wait(self, name: str) -> bool:
"""Clears its wait / limit reset. Returns False if it was not waiting."""
"""Ends the wait now (its Wait tasks become Limit reset). False if it was not waiting."""
was_waiting = ctypes.c_int(0)
self._call("lls_account_clear_wait", _enc(name), ctypes.byref(was_waiting))
return bool(was_waiting.value)
@@ -402,7 +402,7 @@ class Database:
until=_when(info.until),
notes=_dec(info.notes),
notes_lines=info.notes_lines,
overrides_wait=bool(info.overrides_wait),
account_waiting=bool(info.account_waiting),
))
return result
finally: