h-ai-brain 0.0.7__py3-none-any.whl → 0.0.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- h_ai/domain/priorityqueue/priority_queue_repository.py +5 -5
- h_ai/infrastructure/priorityqueue/in_memory_priority_queue_repository.py +41 -30
- {h_ai_brain-0.0.7.dist-info → h_ai_brain-0.0.8.dist-info}/METADATA +1 -1
- {h_ai_brain-0.0.7.dist-info → h_ai_brain-0.0.8.dist-info}/RECORD +8 -8
- {h_ai_brain-0.0.7.dist-info → h_ai_brain-0.0.8.dist-info}/WHEEL +0 -0
- {h_ai_brain-0.0.7.dist-info → h_ai_brain-0.0.8.dist-info}/licenses/LICENSE +0 -0
- {h_ai_brain-0.0.7.dist-info → h_ai_brain-0.0.8.dist-info}/licenses/NOTICE.txt +0 -0
- {h_ai_brain-0.0.7.dist-info → h_ai_brain-0.0.8.dist-info}/top_level.txt +0 -0
@@ -14,14 +14,14 @@ class PriorityQueueRepository(ABC):
|
|
14
14
|
pass
|
15
15
|
|
16
16
|
@abstractmethod
|
17
|
-
def get_highest_priority_item(self, queue_name: str) -> Optional[QueueItem]:
|
17
|
+
def get_highest_priority_item(self, queue_name: str, block: bool = False, timeout: Optional[float] = None) -> Optional[QueueItem]:
|
18
18
|
"""Get and remove the highest priority item from the queue"""
|
19
19
|
pass
|
20
20
|
|
21
|
-
@abstractmethod
|
22
|
-
def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
|
23
|
-
|
24
|
-
|
21
|
+
# @abstractmethod
|
22
|
+
# def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
|
23
|
+
# """Get multiple items from the queue in priority order without removing them"""
|
24
|
+
# pass
|
25
25
|
|
26
26
|
@abstractmethod
|
27
27
|
def queue_length(self, queue_name: str) -> int:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
import queue
|
2
2
|
import threading
|
3
3
|
from queue import PriorityQueue
|
4
4
|
from typing import Dict, List, Optional
|
@@ -31,56 +31,67 @@ class InMemoryPriorityQueueRepository(PriorityQueueRepository):
|
|
31
31
|
|
32
32
|
def add_item(self, queue_name: str, item: QueueItem) -> None:
|
33
33
|
"""Add an item to the specified queue"""
|
34
|
-
|
34
|
+
q = self._get_or_create_queue(queue_name)
|
35
35
|
with self._get_lock(queue_name):
|
36
36
|
# The queue automatically orders by priority
|
37
|
-
|
37
|
+
q.put(item)
|
38
38
|
|
39
|
-
def get_highest_priority_item(self, queue_name: str) -> Optional[QueueItem]:
|
39
|
+
def get_highest_priority_item(self, queue_name: str, block: bool = False, timeout: Optional[float] = None) -> Optional[QueueItem]:
|
40
40
|
"""Get and remove the highest priority item from the queue"""
|
41
41
|
if queue_name not in self.queues:
|
42
42
|
return None
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
q = self.queues[queue_name]
|
45
|
+
try:
|
46
|
+
# We need to acquire the lock to check initially, but then we need to release it
|
47
|
+
# so that other threads can add items while we're blocking
|
48
|
+
with self._get_lock(queue_name):
|
49
|
+
# If not blocking and queue is empty, return immediately
|
50
|
+
if not block and q.empty():
|
51
|
+
return None
|
52
|
+
|
53
|
+
# Note: queue.get() with block=True will internally manage locking
|
54
|
+
# We don't hold our custom lock during the blocking wait
|
55
|
+
return q.get(block=block, timeout=timeout)
|
56
|
+
except queue.Empty:
|
57
|
+
# This will be raised if timeout occurs with no items
|
58
|
+
return None
|
59
|
+
|
49
60
|
|
50
61
|
def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
"""Get multiple items from the queue in priority order without removing them"""
|
63
|
+
if queue_name not in self.queues:
|
64
|
+
return []
|
54
65
|
|
55
|
-
|
56
|
-
|
66
|
+
q = self.queues[queue_name]
|
67
|
+
result = []
|
57
68
|
|
58
|
-
|
59
|
-
|
60
|
-
|
69
|
+
with self._get_lock(queue_name):
|
70
|
+
# Create a temporary list to hold items that we'll put back
|
71
|
+
temp_items = []
|
61
72
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
# Get up to 'limit' items
|
74
|
+
count = 0
|
75
|
+
while not q.empty() and count < limit:
|
76
|
+
item = q.get()
|
77
|
+
temp_items.append(item)
|
78
|
+
result.append(item)
|
79
|
+
count += 1
|
69
80
|
|
70
|
-
|
71
|
-
|
72
|
-
|
81
|
+
# Put all the items back in the same order
|
82
|
+
for item in temp_items:
|
83
|
+
q.put(item)
|
73
84
|
|
74
|
-
|
85
|
+
return result
|
75
86
|
|
76
87
|
def queue_length(self, queue_name: str) -> int:
|
77
88
|
"""Get the number of items in the queue"""
|
78
89
|
if queue_name not in self.queues:
|
79
90
|
return 0
|
80
91
|
|
81
|
-
|
92
|
+
q = self.queues[queue_name]
|
82
93
|
with self._get_lock(queue_name):
|
83
|
-
return
|
94
|
+
return q.qsize()
|
84
95
|
|
85
96
|
def get_queue_names(self) -> List[str]:
|
86
97
|
"""Get a list of all available queue names"""
|
@@ -7,7 +7,7 @@ h_ai/application/system_prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
7
7
|
h_ai/application/system_prompts/roles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
h_ai/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
h_ai/domain/priorityqueue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
h_ai/domain/priorityqueue/priority_queue_repository.py,sha256=
|
10
|
+
h_ai/domain/priorityqueue/priority_queue_repository.py,sha256=_px-WFlsj439EKV1qN-z85rQDeybhs2p-xGEXRpOtHE,1104
|
11
11
|
h_ai/domain/priorityqueue/queue_item.py,sha256=aP2Sd3ig9dgKnAsKE_rr3uRjJ_ClWIrvz0Y3nC8XbmE,1417
|
12
12
|
h_ai/domain/reasoning/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
h_ai/domain/reasoning/llm_chat_repository.py,sha256=rY2izDyaDnoyyrCRS1qc9erHB98vARj4Mp-SnPwNhyY,211
|
@@ -47,10 +47,10 @@ h_ai/infrastructure/llm/ollama/models/ollama_chat_session.py,sha256=GZ_ddpbWa8iy
|
|
47
47
|
h_ai/infrastructure/playwright/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
48
|
h_ai/infrastructure/playwright/playwright_web_content_fetcher.py,sha256=FVwcK6hv_6aE4fYlJapLHyxNHsztQkKaulklHabyrEc,2684
|
49
49
|
h_ai/infrastructure/priorityqueue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
50
|
-
h_ai/infrastructure/priorityqueue/in_memory_priority_queue_repository.py,sha256
|
51
|
-
h_ai_brain-0.0.
|
52
|
-
h_ai_brain-0.0.
|
53
|
-
h_ai_brain-0.0.
|
54
|
-
h_ai_brain-0.0.
|
55
|
-
h_ai_brain-0.0.
|
56
|
-
h_ai_brain-0.0.
|
50
|
+
h_ai/infrastructure/priorityqueue/in_memory_priority_queue_repository.py,sha256=zxnrbzoLfiKQMB28dI1bPe0qUtvIDG8OEFcTQL_UeFg,3886
|
51
|
+
h_ai_brain-0.0.8.dist-info/licenses/LICENSE,sha256=SbvpEU5JIU3yzMMkyzrI0dGqHDoJR_lMKGdl6GZHsy4,11558
|
52
|
+
h_ai_brain-0.0.8.dist-info/licenses/NOTICE.txt,sha256=vxeIKUiGqAePLvDW4AVm3Xh-3BcsvMtCMn1tbsr9zsE,668
|
53
|
+
h_ai_brain-0.0.8.dist-info/METADATA,sha256=tO3CbkRDXPuG4cTEIPA8sOtgyXqEMk7ew-KBTA0NGUA,735
|
54
|
+
h_ai_brain-0.0.8.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
55
|
+
h_ai_brain-0.0.8.dist-info/top_level.txt,sha256=3MChDBWvDJV4cEHuZhzeODxQ4ewtw-arOuyaDOc6sIo,5
|
56
|
+
h_ai_brain-0.0.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|