删除转移运行

删除 BigQuery Data Transfer Service 中的转移作业运行。

代码示例

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 示例浏览器