检查缓存中是否有超时的任务
(self)
| 579 | self.local_gid += 1 |
| 580 | |
| 581 | def monitor(self): |
| 582 | """检查缓存中是否有超时的任务""" |
| 583 | interval = int(os.environ.get("LOCAL_MONITOR_INTERVAL", "300")) |
| 584 | while True: |
| 585 | time.sleep(interval) |
| 586 | oldest_task = None |
| 587 | |
| 588 | for k, v in list(self.cached_tasks.items()): |
| 589 | if oldest_task is None or v.status.created_time < oldest_task.status.created_time: |
| 590 | oldest_task = v |
| 591 | |
| 592 | if (datetime.datetime.now() - v.status.created_time).total_seconds() > self.timeout: |
| 593 | logger.warning(f"Task {v.status.task_id}, completion {k} is out of time.") |
| 594 | # del self.cached_tasks[k] |
| 595 | |
| 596 | if oldest_task is not None: |
| 597 | logger.info(f"[ Local GID: {self.local_gid} | Cached: {len(self.cached_tasks)}, " |
| 598 | f"Reprocessing: {self.valid_tasks.qsize()} | Queued: {self.ready_queue.qsize()} ] " |
| 599 | f"The oldest task id {oldest_task.status.task_id}, " |
| 600 | f"create time: {oldest_task.status.created_time}") |
| 601 | |
| 602 | def start(self): |
| 603 | """启动所有线程并运行主循环""" |
nothing calls this directly
no outgoing calls
no test coverage detected