forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_first_intent_queue.py
More file actions
35 lines (26 loc) · 878 Bytes
/
Copy pathchat_first_intent_queue.py
File metadata and controls
35 lines (26 loc) · 878 Bytes
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
"""Chat-first ready-intent drain: substrate sort plus per-item isolation.
Kept out of ``chat_first_intents.py`` so that 1,500-line file does not grow.
"""
from __future__ import annotations
from typing import Any, Callable, Iterable, List, Sequence, TypeVar
from database.durable_queue import ProcessOutcome, drain_isolated, ready_sort_key
T = TypeVar('T')
def sort_ready_intents(
intents: Sequence[Any],
*,
priority_of: Callable[[Any], int],
) -> List[Any]:
return sorted(
intents,
key=lambda intent: ready_sort_key(
priority=priority_of(intent),
created_at=intent.created_at,
item_id=intent.intent_id,
enable_priority=True,
),
)
def drain_intent_batch(
items: Iterable[T],
process_one: Callable[[T], ProcessOutcome],
) -> None:
drain_isolated(items, process_one)