Check job status

Checks the status of a job.

Code sample

Python

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

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser