Get job (v1beta3)

Get an existing Dataflow job by ID.

Code sample

Go

To authenticate to Dataflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import (
	"context"
	"fmt"
	"io"

	dataflow "cloud.google.com/go/dataflow/apiv1beta3"
	dataflowpb "cloud.google.com/go/dataflow/apiv1beta3/dataflowpb"
)

// getJob gets an existing Cloud Dataflow job by ID.
func getJob(ctx context.Context, w io.Writer, projectID string, locationID string, jobID string) error {
	client, err := dataflow.NewJobsV1Beta3Client(ctx)
	if err != nil {
		return fmt.Errorf("NewJobsV1Beta3Client failed: %w", err)
	}
	defer client.Close()

	req := &dataflowpb.GetJobRequest{
		ProjectId: projectID,
		Location:  locationID,
		JobId:     jobID,
		View:      dataflowpb.JobView_JOB_VIEW_SUMMARY,
	}

	job, err := client.GetJob(ctx, req)
	if err != nil {
		return fmt.Errorf("GetJob: %w", err)
	}

	fmt.Fprintf(w, "Job ID: %s\nState: %s\nType: %s\n", job.GetId(), job.GetCurrentState(), job.GetType())
	return nil
}

What's next

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