작업 삭제 및 내보내기

이 페이지에서는 일괄 작업을 삭제하고 내보내는 방법을 설명합니다.

작업이 삭제되면 작업과 해당 태스크를 확인할 때 표시되는 작업의 세부정보와 기록이 일괄 작업에서 삭제됩니다. 작업과 관련된 모든 정보와 리소스를 삭제하려면 Pub/Sub 주제, BigQuery 테이블, 또는 Cloud Logging 로그와 같이 사용 설정한 추가 Google Cloud 제품에서도 항목을 삭제해야 합니다.

Google Cloud는 작업이 실패하거나 성공하면 60일 후에 작업이 자동으로 삭제됩니다. 작업이 자동으로 삭제되기 전에 선택적으로 다음 중 하나를 수행할 수 있습니다.

  • 작업 내보내기: 작업 정보를 60일 이상 보관하려면 다음 중 하나를 수행합니다.

  • 작업 삭제: 이 문서에 설명된 대로 프로젝트의 작업 목록에서 삭제할 준비가 되고 더 이상 작업 기록이 필요하지 않으면 작업을 수동으로 삭제할 수 있습니다. 실행 중 또는 실행 중에 작업을 삭제하면 작업이 취소됩니다.

시작하기 전에

작업 삭제

Google Cloud 콘솔, gcloud CLI, Batch API, Go, Java, Node.js, Python 또는 C++를 사용하여 작업을 삭제할 수 있습니다.

콘솔

Google Cloud 콘솔을 사용하여 작업을 삭제하려면 다음 단계를 따르세요.

  1. Google Cloud 콘솔에서 작업 목록 페이지로 이동합니다.

    작업 목록으로 이동

  2. 만든 작업의 이름을 클릭합니다. 작업 세부정보 페이지가 열립니다.

  3. 삭제를 클릭합니다.

  4. 일괄 작업을 삭제하시겠습니까? 대화상자의 필드에 Delete를 입력합니다.

  5. Delete(삭제)를 클릭합니다.

    작업 목록 페이지에 작업이 삭제되었음을 표시합니다.

gcloud

gcloud CLI를 사용하여 작업을 삭제하려면 gcloud batch jobs delete 명령어를 사용합니다.

gcloud batch jobs delete JOB_NAME --location LOCATION

다음을 바꿉니다.

  • JOB_NAME: 작업의 이름
  • LOCATION: 작업의 위치

API

Batch API를 사용하여 작업을 설명하려면 jobs.delete 메서드를 사용합니다.

DELETE https://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs/JOB_NAME

다음을 바꿉니다.

Go

Go

자세한 내용은 Batch Go API 참조 문서를 확인하세요.

Batch에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import (
	"context"
	"fmt"
	"io"

	batch "cloud.google.com/go/batch/apiv1"
	"cloud.google.com/go/batch/apiv1/batchpb"
)

// Deletes the specified job
func deleteJob(w io.Writer, projectID, region, jobName string) error {
	// projectID := "your_project_id"
	// region := "us-central1"
	// jobName := "some-job"

	ctx := context.Background()
	batchClient, err := batch.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer batchClient.Close()

	req := &batchpb.DeleteJobRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, region, jobName),
	}

	response, err := batchClient.DeleteJob(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to delete job: %w", err)
	}

	fmt.Fprintf(w, "Job deleted: %v\n", response)

	return nil
}

Java

Java

자세한 내용은 Batch Java API 참조 문서를 확인하세요.

Batch에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import com.google.cloud.batch.v1.BatchServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteJob {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // Name of the region hosts the job.
    String region = "europe-central2";

    // The name of the job that you want to delete.
    String jobName = "JOB_NAME";

    deleteJob(projectId, region, jobName);
  }

  // Triggers the deletion of a Job.
  public static void deleteJob(String projectId, String region, String jobName)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `batchServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (BatchServiceClient batchServiceClient = BatchServiceClient.create()) {

      // Construct the parent path of the job.
      String name = String.format("projects/%s/locations/%s/jobs/%s", projectId, region, jobName);

      batchServiceClient.deleteJobAsync(name).get(5, TimeUnit.MINUTES);
      System.out.printf("Delete the job: %s", jobName);
    }
  }
}

Node.js

Node.js

자세한 내용은 Batch Node.js API 참조 문서를 확인하세요.

Batch에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
/**
 * The region that hosts the job.
 */
// const region = 'us-central-1';
/**
 * The name of the job you want to delete.
 */
// const jobName = 'YOUR_JOB_NAME';

// Imports the Batch library
const batchLib = require('@google-cloud/batch');

// Instantiates a client
const batchClient = new batchLib.v1.BatchServiceClient();

async function callDeleteJob() {
  // Construct request
  const request = {
    name: `projects/${projectId}/locations/${region}/jobs/${jobName}`,
  };

  // Run request
  const [operation] = await batchClient.deleteJob(request);
  const [response] = await operation.promise();
  console.log(response);
}

callDeleteJob();

Python

Python

자세한 내용은 Batch Python API 참조 문서를 확인하세요.

Batch에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

from google.api_core.operation import Operation

from google.cloud import batch_v1

def delete_job(project_id: str, region: str, job_name: str) -> Operation:
    """
    Triggers the deletion of a Job.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        region: name of the region hosts the job.
        job_name: the name of the job that you want to delete.

    Returns:
        An operation object related to the deletion. You can call `.result()`
        on it to wait for its completion.
    """
    client = batch_v1.BatchServiceClient()

    return client.delete_job(
        name=f"projects/{project_id}/locations/{region}/jobs/{job_name}"
    )

C++

C++

자세한 내용은 Batch C++ API 참조 문서를 확인하세요.

Batch에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

#include "google/cloud/batch/v1/batch_client.h"

  [](std::string const& project_id, std::string const& location_id,
     std::string const& job_id) {
    auto const name = "projects/" + project_id + "/locations/" + location_id +
                      "/jobs/" + job_id;
    google::cloud::batch::v1::DeleteJobRequest request;
    request.set_name(name);
    // Initialize a client and issue the request.
    auto client = google::cloud::batch_v1::BatchServiceClient(
        google::cloud::batch_v1::MakeBatchServiceConnection());
    auto future = client.DeleteJob(request);
    // Wait until the long-running operation completes.
    auto success = future.get();
    if (!success) throw std::move(success).status();
    std::cout << "Job " << name << " successfully deleted\n";
  }

다음 단계