MCPcopy Create free account
hub / github.com/GerevAI/gerev / TaskQueue

Class TaskQueue

app/queues/task_queue.py:24–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24class TaskQueue(SQLiteAckQueue):
25 _instance = None
26 _lock = threading.Lock()
27
28 @classmethod
29 def get_instance(cls):
30 with cls._lock:
31 if cls._instance is None:
32 cls._instance = cls()
33 return cls._instance
34
35 def __init__(self):
36 if TaskQueue._instance is not None:
37 raise RuntimeError("TaskQueue is a singleton, use .get() to get the instance")
38
39 self.condition = threading.Condition()
40 super().__init__(path=SQLITE_TASKS_PATH, multithreading=True, name="task")
41
42 def add_task(self, task: Task):
43 self.put(task)
44
45 def get_task(self, timeout=1) -> Optional[TaskQueueItem]:
46 try:
47 raw_item = super().get(raw=True, block=True, timeout=timeout)
48 return TaskQueueItem(queue_item_id=raw_item['pqid'], task=raw_item['data'])
49
50 except Empty:
51 return None

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected