def get_scheduled_history(self,job_id): req = master_pb2.ListTaskRequest() req.job_id = job_id master = master_pb2.Master_Stub(self.channel) controller = client.Controller() controller.SetTimeout(3.5) try: response = master.ListTask(controller,req) if not response: LOG.error('fail to list task %s'%job_id) return False,[] ret = [] for task in response.scheduled_tasks: base = BaseEntity() base.id = task.info.task_id base.status = STATE_MAP[task.status] base.name = task.info.task_name base.agent_addr = task.agent_addr base.job_id = task.job_id base.offset = task.offset base.mem_limit = task.info.required_mem base.cpu_limit = task.info.required_cpu base.mem_used = task.memory_usage base.cpu_used = task.cpu_usage base.start_time = task.start_time base.gc_path = task.root_path base.end_time = datetime.datetime.fromtimestamp(task.end_time).strftime("%m-%d %H:%M:%S") ret.append(base) return True,ret except: LOG.exception('fail to list task history') return False,[]
def list_task_by_job_id(self,job_id): req = master_pb2.ListTaskRequest() req.job_id = job_id master = master_pb2.Master_Stub(self.channel) controller = client.Controller() controller.SetTimeout(3.5) try: response = master.ListTask(controller,req) if not response: LOG.error('fail to list task %s'%job_id) return False,[] ret = [] for task in response.tasks: base = BaseEntity() base.id = task.info.task_id base.status = STATE_MAP[task.status] base.name = task.info.task_name base.agent_addr = task.agent_addr base.job_id = task.job_id base.offset = task.offset base.mem_limit = task.info.required_mem base.cpu_limit = task.info.required_cpu base.mem_used = task.memory_usage base.cpu_used = task.cpu_usage base.start_time = task.start_time ret.append(base) return True,ret except: LOG.exception('fail to list task') return False,[]