刪除轉移作業

刪除 BigQuery 資料移轉服務中的移轉作業執行。

程式碼範例

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();

/**
 * Deletes a transfer run.
 * This action removes a specific execution instance of a 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, '1234a123-123a-123a-123a-123456789abc').
 * @param {string} runId The ID of the transfer run (for example, '9876b987-987b-987b-987b-987654321cba').
 */
async function deleteTransferRun(
  projectId,
  location = 'us-central1',
  transferConfigId = '1234a123-123a-123a-123a-123456789abc',
  runId = '9876b987-987b-987b-987b-987654321cba',
) {
  const name = client.projectLocationTransferConfigRunPath(
    projectId,
    location,
    transferConfigId,
    runId,
  );
  const request = {
    name,
  };

  try {
    await client.deleteTransferRun(request);
    console.log(`Deleted transfer run ${name}.`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Transfer run ${name} not found.`);
    } else {
      console.error('Error deleting transfer run:', err);
    }
  }
}

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器