def kill_job(job_id, role, party_id, job_initiator, timeout=False, component_name=''): schedule_logger(job_id).info('{} {} get kill job {} {} command'.format(role, party_id, job_id, component_name)) task_info = job_utils.get_task_info(job_id, role, party_id, component_name) tasks = job_utils.query_task(**task_info) job = job_utils.query_job(job_id=job_id) for task in tasks: kill_status = False try: # task clean up runtime_conf = json_loads(job[0].f_runtime_conf) roles = ','.join(runtime_conf['role'].keys()) party_ids = ','.join([','.join([str(j) for j in i]) for i in runtime_conf['role'].values()]) # Tracking(job_id=job_id, role=role, party_id=party_id, task_id=task.f_task_id).clean_task(roles, party_ids) # stop task kill_status = job_utils.kill_task_executor_process(task) # session stop job_utils.start_session_stop(task) except Exception as e: schedule_logger(job_id).exception(e) finally: schedule_logger(job_id).info( 'job {} component {} on {} {} process {} kill {}'.format(job_id, task.f_component_name, task.f_role, task.f_party_id, task.f_run_pid, 'success' if kill_status else 'failed')) status = TaskStatus.FAILED if not timeout else TaskStatus.TIMEOUT if task.f_status != TaskStatus.COMPLETE: task.f_status = status try: TaskExecutor.sync_task_status(job_id=job_id, component_name=task.f_component_name, task_id=task.f_task_id, role=role, party_id=party_id, initiator_party_id=job_initiator.get('party_id', None), task_info=task.to_json(), initiator_role=job_initiator.get('role', None)) except Exception as e: schedule_logger(job_id).exception(e)
def kill(task): kill_status_code = job_utils.kill_task_executor_process(task) # session stop if kill_status_code == KillProcessStatusCode.KILLED or task.f_status not in { TaskStatus.WAITING }: job_utils.start_session_stop(task)
def kill_task(cls, task: Task): kill_status = False try: # kill task executor kill_status_code = job_utils.kill_task_executor_process(task) # session stop if kill_status_code == KillProcessStatusCode.KILLED or task.f_status not in { TaskStatus.WAITING }: job_utils.start_session_stop(task) except Exception as e: schedule_logger(task.f_job_id).exception(e) else: kill_status = True finally: schedule_logger(task.f_job_id).info( 'job {} task {} {} on {} {} process {} kill {}'.format( task.f_job_id, task.f_task_id, task.f_task_version, task.f_role, task.f_party_id, task.f_run_pid, 'success' if kill_status else 'failed')) return kill_status