Check job status

Checks the status of a job.

Code sample


Before trying this sample, follow the Python setup instructions in the Dataproc quickstart using client libraries. For more information, see the Dataproc Python API reference documentation.

def wait_for_job(dataproc, project, region, job_id):
    """Wait for job to complete or error out."""
    print("Waiting for job to finish...")
    while True:
        job = dataproc.get_job(
            request={"project_id": project, "region": region, "job_id": job_id}
        # Handle exceptions
        if job.status.State.Name(job.status.state) == "ERROR":
            raise Exception(job.status.details)
        elif job.status.State.Name(job.status.state) == "DONE":
            print("Job finished.")
            return job

What's next
