# coding=utf-8 """ @Time :2026/6/24 @Author :tao.chen """ from common.logging import logger from spark_executor.core.yarn_client import YarnClientConfig from spark_executor.core.job_store import JobStore from spark_executor.core.yarn_client import get_application_status from spark_executor.models import JobStatus from spark_executor.tools.connections import store as conn_store from spark_executor.tools.logs import _unknown_job_error store = JobStore() def get_job_status(job_id: str) -> JobStatus: """Query YARN for a job's current status. `job_id` accepts either the local job_id (returned by confirm_submit_job) or the YARN application_id. """ logger.debug(f"get_job_status enter job_id={job_id}") job = store.get_either(job_id) if job is None: raise _unknown_job_error( job_id, external_tool_hint="get_external_job_status(application_id, connection_name)", ) conn = conn_store.get(job.connection) if conn is None: raise KeyError(f"Connection not found: {job.connection}") config = YarnClientConfig.from_connection(conn) state, raw = get_application_status(job.application_id, config) logger.info(f"get_job_status ok job_id={job.job_id} application_id={job.application_id} state={state}") return JobStatus(application_id=job.application_id, state=state, raw=raw)