워크플로의 모든 이전 하위 작업 나열

지정된 마이그레이션 워크플로의 모든 마이그레이션 하위 작업을 나열합니다. 이를 사용하여 더 큰 BigQuery 마이그레이션 내 개별 단계의 상태를 모니터링합니다.

코드 샘플

Node.js

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

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

const {MigrationServiceClient} = require('@google-cloud/bigquery-migration').v2;
const {status} = require('@grpc/grpc-js');

const client = new MigrationServiceClient();

/**
 * Lists all migration subtasks for a given workflow.
 *
 * This is useful to track the progress of a migration by by examining its
 * individual steps.
 *
 * @param {string} projectId The Google Cloud project ID (for example, 'example-project-id').
 * @param {string} location The Google Cloud location of the workflow (for example, 'us').
 * @param {string} workflowId The ID of the migration workflow (for example, '12345678-abcd-4372-a567-0e02b2c3d479').
 */
async function listMigrationSubtasks(projectId, location, workflowId) {
  const parent = client.migrationWorkflowPath(projectId, location, workflowId);
  const request = {
    parent,
  };

  try {
    const [subtasks] = await client.listMigrationSubtasks(request);

    if (subtasks.length === 0) {
      console.error(`No subtasks found for workflow ${parent}.`);
      return;
    }

    console.log(`Subtasks for workflow: ${parent}`);
    for (const subtask of subtasks) {
      console.log(`  Subtask Name: ${subtask.name}`);
      console.log(`    Type: ${subtask.type}`);
      console.log(`    State: ${subtask.state}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Workflow not found: ${parent}`);
    } else {
      console.error('Error listing migration subtasks:', err);
    }
  }
}

Python

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

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

from google.api_core.exceptions import NotFound
from google.cloud import bigquery_migration_v2

client = bigquery_migration_v2.MigrationServiceClient()


def list_migration_subtasks(project_id: str, location: str, workflow_id: str) -> None:
    """Lists migration subtasks for a given workflow.

    Args:
        project_id: The Google Cloud project ID.
        location: The location of the migration workflow, for example, "us".
        workflow_id: The ID of the migration workflow.
    """

    parent = client.migration_workflow_path(project_id, location, workflow_id)

    try:
        print(f"Listing migration subtasks for workflow: {workflow_id}")
        subtasks = client.list_migration_subtasks(parent=parent)
        for subtask in subtasks:
            print(f"  Subtask Name: {subtask.name}")
            print(f"    Type: {subtask.type_}")
            print(f"    State: {subtask.state.name}")
    except NotFound:
        print(f"Migration workflow not found: {parent}")

다음 단계

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