Get transfer run metadata Stay organized with collections Save and categorize content based on your preferences.
Get information about a particular run of a scheduled transfer configuration.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Java
Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importcom.google.api.gax.rpc.ApiException;importcom.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;importcom.google.cloud.bigquery.datatransfer.v1.GetTransferRunRequest;importcom.google.cloud.bigquery.datatransfer.v1.TransferRun;importjava.io.IOException;// Sample to get run details from transfer config.publicclassRunDetails{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.// runId examples:// `projects/{project_id}/transferConfigs/{config_id}/runs/{run_id}` or// `projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}/runs/{run_id}`StringrunId="MY_RUN_ID";runDetails(runId);}publicstaticvoidrunDetails(StringrunId)throwsIOException{try(DataTransferServiceClientdataTransferServiceClient=DataTransferServiceClient.create()){GetTransferRunRequestrequest=GetTransferRunRequest.newBuilder().setName(runId).build();TransferRunrun=dataTransferServiceClient.getTransferRun(request);System.out.print("Run details retrieved successfully :"+run.getName()+"\n");}catch(ApiExceptionex){System.out.print("Run details not found."+ex.toString());}}}Node.js
Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
const{DataTransferServiceClient,}=require('@google-cloud/bigquery-data-transfer');const{status}=require('@grpc/grpc-js');constclient=newDataTransferServiceClient();/** * Gets a transfer run. * A transfer run represents a single execution of a data transfer configuration. * * @param {string} projectId The Google Cloud project ID, for example 'example-project-id'. * @param {string} location The location of the transfer config, for example 'us-central1'. * @param {string} transferConfigId The ID of the transfer configuration, for example '1234a-5678-9012b'. * @param {string} runId The ID of the transfer run, for example 'abcdef-0123-4567-8901-fedcba987654'. */asyncfunctiongetTransferRun(projectId,location='us-central1',transferConfigId='1234a-5678-9012b',runId='abcdef-0123-4567-8901-fedcba987654',){constname=client.projectLocationTransferConfigRunPath(projectId,location,transferConfigId,runId,);constrequest={name,};try{const[run]=awaitclient.getTransferRun(request);console.log(`Got transfer run:${run.name}`);console.log(` Data Source Id:${run.dataSourceId}`);if(run.runTime &&run.runTime.seconds){console.log(` Run time:${newDate(run.runTime.seconds*1000).toISOString()}`,);}console.log(` State:${run.state}`);}catch(err){if(err.code===status.NOT_FOUND){console.error(`Transfer run${name} not found.`);}else{console.error(`Error getting transfer run${name}:`,err);}}}Python
Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_datatransfer_v1client=bigquery_datatransfer_v1.DataTransferServiceClient()defget_transfer_run(project_id:str,location:str,transfer_config_id:str,run_id:str,)->None:"""Gets information about a transfer run. Args: project_id: The Google Cloud project ID. location: The geographic location of the transfer run, for example, 'us' or 'europe-west1'. transfer_config_id: The transfer configuration ID. run_id: The transfer run ID. """run_name=client.run_path(project=f"{project_id}/locations/{location}",transfer_config=transfer_config_id,run=run_id,)try:transfer_run=client.get_transfer_run(name=run_name)print(f"Got transfer run:{transfer_run.name}")print(f"State:{transfer_run.state.name}")exceptgoogle.api_core.exceptions.NotFound:print(f"Error: Transfer run '{run_name}' not found.")What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.