ジョブの削除
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Batch ジョブの削除をトリガーします。
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content provides code samples in C++, Go, Java, Node.js, and Python for deleting a Batch job.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code samples use the Batch API to delete a specified job by its project ID, region, and job name.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample requires setting up Application Default Credentials for authentication to access Batch services.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples utilize a BatchServiceClient or similar client instantiation to handle the deletion request and long-running operation status.\u003c/p\u003e\n"],["\u003cp\u003eReferencing the respective Batch API documentation for each language (C++, Go, Java, Node.js, Python) is recommended for more detailed information on the Batch API.\u003c/p\u003e\n"]]],[],null,["# Delete a job\n\nTrigger the deletion of a Batch job.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Delete jobs](/batch/docs/delete-job)\n\nCode sample\n-----------\n\n### C++\n\n\nFor more information, see the\n[Batch C++ API\nreference documentation](/cpp/docs/reference/batch/latest).\n\n\nTo authenticate to Batch, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n #include \"google/cloud/batch/v1/batch_client.h\"\n\n [](std::string const& project_id, std::string const& location_id,\n std::string const& job_id) {\n auto const name = \"projects/\" + project_id + \"/locations/\" + location_id +\n \"/jobs/\" + job_id;\n google::cloud::batch::v1::DeleteJobRequest request;\n request.set_name(name);\n // Initialize a client and issue the request.\n auto client = google::cloud::batch_v1::BatchServiceClient(\n google::cloud::batch_v1::MakeBatchServiceConnection());\n auto future = client.DeleteJob(request);\n // Wait until the long-running operation completes.\n auto success = future.get();\n if (!success) throw std::move(success).status();\n std::cout \u003c\u003c \"Job \" \u003c\u003c name \u003c\u003c \" successfully deleted\\n\";\n }\n\n### Go\n\n\nFor more information, see the\n[Batch Go API\nreference documentation](/go/docs/reference/cloud.google.com/go/batch/latest/apiv1).\n\n\nTo authenticate to Batch, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tbatch \"cloud.google.com/go/batch/apiv1\"\n \t\"cloud.google.com/go/batch/apiv1/batchpb\"\n )\n\n // Deletes the specified job\n func deleteJob(w io.Writer, projectID, region, jobName string) error {\n \t// projectID := \"your_project_id\"\n \t// region := \"us-central1\"\n \t// jobName := \"some-job\"\n\n \tctx := context.Background()\n \tbatchClient, err := batch.https://cloud.google.com/go/docs/reference/cloud.google.com/go/batch/latest/apiv1.html#cloud_google_com_go_batch_apiv1_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"NewClient: %w\", err)\n \t}\n \tdefer batchClient.Close()\n\n \treq := &batchpb.DeleteJobRequest{\n \t\tName: fmt.Sprintf(\"projects/%s/locations/%s/jobs/%s\", projectID, region, jobName),\n \t}\n\n \tresponse, err := batchClient.DeleteJob(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"unable to delete job: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Job deleted: %v\\n\", response)\n\n \treturn nil\n }\n\n### Java\n\n\nFor more information, see the\n[Batch Java API\nreference documentation](/java/docs/reference/google-cloud-batch/latest/overview).\n\n\nTo authenticate to Batch, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.batch.v1.https://cloud.google.com/java/docs/reference/google-cloud-batch/latest/com.google.cloud.batch.v1.BatchServiceClient.html;\n import java.io.IOException;\n import java.util.concurrent.ExecutionException;\n import java.util.concurrent.TimeUnit;\n import java.util.concurrent.TimeoutException;\n\n public class DeleteJob {\n\n public static void main(String[] args)\n throws IOException, ExecutionException, InterruptedException, TimeoutException {\n // TODO(developer): Replace these variables before running the sample.\n // Project ID or project number of the Cloud project you want to use.\n String projectId = \"YOUR_PROJECT_ID\";\n\n // Name of the region hosts the job.\n String region = \"europe-central2\";\n\n // The name of the job that you want to delete.\n String jobName = \"JOB_NAME\";\n\n deleteJob(projectId, region, jobName);\n }\n\n // Triggers the deletion of a Job.\n public static void deleteJob(String projectId, String region, String jobName)\n throws IOException, ExecutionException, InterruptedException, TimeoutException {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the `batchServiceClient.close()` method on the client to safely\n // clean up any remaining background resources.\n try (https://cloud.google.com/java/docs/reference/google-cloud-batch/latest/com.google.cloud.batch.v1.BatchServiceClient.html batchServiceClient = https://cloud.google.com/java/docs/reference/google-cloud-batch/latest/com.google.cloud.batch.v1.BatchServiceClient.html.create()) {\n\n // Construct the parent path of the job.\n String name = String.format(\"projects/%s/locations/%s/jobs/%s\", projectId, region, jobName);\n\n batchServiceClient.https://cloud.google.com/java/docs/reference/google-cloud-batch/latest/com.google.cloud.batch.v1.BatchServiceClient.html#com_google_cloud_batch_v1_BatchServiceClient_deleteJobAsync_com_google_cloud_batch_v1_DeleteJobRequest_(name).get(5, TimeUnit.MINUTES);\n System.out.printf(\"Delete the job: %s\", jobName);\n }\n }\n }\n\n### Node.js\n\n\nFor more information, see the\n[Batch Node.js API\nreference documentation](/nodejs/docs/reference/batch/latest).\n\n\nTo authenticate to Batch, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n /**\n * TODO(developer): Uncomment and replace these variables before running the sample.\n */\n // const projectId = 'YOUR_PROJECT_ID';\n /**\n * The region that hosts the job.\n */\n // const region = 'us-central-1';\n /**\n * The name of the job you want to delete.\n */\n // const jobName = 'YOUR_JOB_NAME';\n\n // Imports the Batch library\n const batchLib = require('https://cloud.google.com/nodejs/docs/reference/batch/latest/overview.html');\n\n // Instantiates a client\n const batchClient = new batchLib.v1.https://cloud.google.com/nodejs/docs/reference/batch/latest/overview.html();\n\n async function callDeleteJob() {\n // Construct request\n const request = {\n name: `projects/${projectId}/locations/${region}/jobs/${jobName}`,\n };\n\n // Run request\n const [operation] = await batchClient.deleteJob(request);\n const [response] = await operation.promise();\n console.log(response);\n }\n\n await callDeleteJob();\n\n### Python\n\n\nFor more information, see the\n[Batch Python API\nreference documentation](/python/docs/reference/batch/latest).\n\n\nTo authenticate to Batch, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.api_core.operation import Operation\n\n from google.cloud import batch_v1\n\n\n def delete_job(project_id: str, region: str, job_name: str) -\u003e Operation:\n \"\"\"\n Triggers the deletion of a Job.\n\n Args:\n project_id: project ID or project number of the Cloud project you want to use.\n region: name of the region hosts the job.\n job_name: the name of the job that you want to delete.\n\n Returns:\n An operation object related to the deletion. You can call `.result()`\n on it to wait for its completion.\n \"\"\"\n client = batch_v1.https://cloud.google.com/python/docs/reference/batch/latest/google.cloud.batch_v1.services.batch_service.BatchServiceClient.html()\n\n return client.https://cloud.google.com/python/docs/reference/batch/latest/google.cloud.batch_v1.services.batch_service.BatchServiceClient.html#google_cloud_batch_v1_services_batch_service_BatchServiceClient_delete_job(\n name=f\"projects/{project_id}/locations/{region}/jobs/{job_name}\"\n )\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=batch)."]]