전송 실행 가져오기

BigQuery Data Transfer Service에서 특정 전송 실행에 관한 정보를 가져옵니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

Java

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Java 설정 안내를 따르세요. 자세한 내용은 BigQuery Java API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

import com.google.api.gax.rpc.ApiException;
import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;
import com.google.cloud.bigquery.datatransfer.v1.GetTransferRunRequest;
import com.google.cloud.bigquery.datatransfer.v1.TransferRun;
import java.io.IOException;

// Sample to get run details from transfer config.
public class RunDetails {

  public static void main(String[] args) throws IOException {
    // 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}`
    String runId = "MY_RUN_ID";
    runDetails(runId);
  }

  public static void runDetails(String runId) throws IOException {
    try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
      GetTransferRunRequest request = GetTransferRunRequest.newBuilder().setName(runId).build();
      TransferRun run = dataTransferServiceClient.getTransferRun(request);
      System.out.print("Run details retrieved successfully :" + run.getName() + "\n");
    } catch (ApiException ex) {
      System.out.print("Run details not found." + ex.toString());
    }
  }
}

Node.js

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Node.js 설정 안내를 따르세요. 자세한 내용은 BigQuery Node.js API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

const {
  DataTransferServiceClient,
} = require('@google-cloud/bigquery-data-transfer');
const {status} = require('@grpc/grpc-js');

const client = new DataTransferServiceClient();

/**
 * 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'.
 */
async function getTransferRun(
  projectId,
  location = 'us-central1',
  transferConfigId = '1234a-5678-9012b',
  runId = 'abcdef-0123-4567-8901-fedcba987654',
) {
  const name = client.projectLocationTransferConfigRunPath(
    projectId,
    location,
    transferConfigId,
    runId,
  );
  const request = {
    name,
  };

  try {
    const [run] = await client.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: ${new Date(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

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 BigQuery Python API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

import google.api_core.exceptions
from google.cloud import bigquery_datatransfer_v1


client = bigquery_datatransfer_v1.DataTransferServiceClient()


def get_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}")
    except google.api_core.exceptions.NotFound:
        print(f"Error: Transfer run '{run_name}' not found.")

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.