def __init__(self, bucket: ObservationBucket, q: WorkQ, q_name: str, sampling_interval: float = 1.0): super().__init__(sleep_interval=sampling_interval) self._bucket = bucket self._q_man = QMan(q) self._q_name = q_name
class WorkQSizeSampler(BackgroundRepeater): @staticmethod def size_label(q_name: str) -> str: return f"q:{q_name}:size" def __init__(self, bucket: ObservationBucket, q: WorkQ, q_name: str, sampling_interval: float = 1.0): super().__init__(sleep_interval=sampling_interval) self._bucket = bucket self._q_man = QMan(q) self._q_name = q_name def _do_run(self) -> bool: try: size = self._q_man.count_pending_tasks(task_id_prefix=None) label = self.size_label(self._q_name) self._bucket.put(observe(label, float(size))) except Exception as e: print(e) return False def _stop(self): self._bucket.empty() def kill(self): super().kill() self._stop()
def list_insert_tasks_runtime_info(): task_id_prefix = build_task_id_init_segment() response_payload = QMan.load_tasks_runtime_info(task_id_prefix) log().info( "Retrieved summary of notification tasks to the work queue successfully" ) return build_json_array_response_stream(response_payload)
def insert_task_count_calculator(task_status: Optional[str] = None) \ -> Callable[[Optional[str]], int]: qman = QMan(InsertAction.insert_queue()) if task_status == TaskStatus.PENDING.value: return qman.count_pending_tasks if task_status == TaskStatus.SUCCEEDED.value: return qman.count_successful_tasks if task_status == TaskStatus.FAILED.value: return qman.count_failed_tasks return qman.count_all_tasks
def insert_task_finder(task_status: Optional[str] = None) \ -> Callable[[str], Iterable[TaskInfo]]: qman = QMan(InsertAction.insert_queue()) if task_status == TaskStatus.PENDING.value: return qman.load_pending_tasks if task_status == TaskStatus.SUCCEEDED.value: return qman.load_successful_tasks if task_status == TaskStatus.FAILED.value: return qman.load_failed_tasks return qman.load_tasks
def delete_insert_tasks(): qman = QMan(InsertAction.insert_queue()) task_id_prefix = build_task_id_init_segment() qman.delete_tasks(task_id_prefix)
def list_insert_tasks_runtime_info(): task_id_prefix = build_task_id_init_segment() response_payload = QMan.load_tasks_runtime_info(task_id_prefix) return build_json_array_response_stream(response_payload)
def delete_insert_tasks(): qman = QMan(InsertAction.insert_queue()) task_id_prefix = build_task_id_init_segment() qman.delete_tasks(task_id_prefix) log().info("Deleted notifcation tasks from the work queue successfully")