ジョブの削除

コード変換ジョブを削除します。

もっと見る

このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。

コードサンプル

C#

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある C# の設定手順を行ってください。 詳細については、Transcoder API C# の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


using Google.Cloud.Video.Transcoder.V1;

public class DeleteJobSample
{
    public void DeleteJob(string projectId, string location, string jobId)
    {
        // Create the client.
        TranscoderServiceClient client = TranscoderServiceClient.Create();

        // Build the job name.
        JobName jobName = JobName.FromProjectLocationJob(projectId, location, jobId);

        // Call the API.
        client.DeleteJob(jobName);
    }
}

Go

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある Go の設定手順を行ってください。 詳細については、Transcoder API Go の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import (
	"context"
	"fmt"
	"io"

	transcoder "cloud.google.com/go/video/transcoder/apiv1"
	"cloud.google.com/go/video/transcoder/apiv1/transcoderpb"
)

// deleteJob deletes a previously-created job. See
// https://cloud.google.com/transcoder/docs/how-to/jobs#delete_jobs for more
// information.
func deleteJob(w io.Writer, projectID string, location string, jobID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// jobID := "my-job-id"
	ctx := context.Background()
	client, err := transcoder.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &transcoderpb.DeleteJobRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, location, jobID),
	}

	err = client.DeleteJob(ctx, req)
	if err != nil {
		return fmt.Errorf("DeleteJob: %w", err)
	}

	fmt.Fprintf(w, "Deleted job")
	return nil
}

Java

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある Java の設定手順を行ってください。 詳細については、Transcoder API Java の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


import com.google.cloud.video.transcoder.v1.DeleteJobRequest;
import com.google.cloud.video.transcoder.v1.JobName;
import com.google.cloud.video.transcoder.v1.TranscoderServiceClient;
import java.io.IOException;

public class DeleteJob {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String location = "us-central1";
    String jobId = "my-job-id";

    deleteJob(projectId, location, jobId);
  }

  // Deletes a job.
  public static void deleteJob(String projectId, String location, String jobId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
      JobName jobName =
          JobName.newBuilder().setProject(projectId).setLocation(location).setJob(jobId).build();
      DeleteJobRequest deleteJobRequest = DeleteJobRequest.newBuilder().setName(jobName.toString())
          .build();

      // Send the delete job request and process the response.
      transcoderServiceClient.deleteJob(deleteJobRequest);
      System.out.println("Deleted job");
    }
  }
}

Node.js

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある Node.js の設定手順を行ってください。 詳細については、Transcoder API Node.js の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// projectId = 'my-project-id';
// location = 'us-central1';
// jobId = 'my-job-id';

// Imports the Transcoder library
const {TranscoderServiceClient} =
  require('@google-cloud/video-transcoder').v1;

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function deleteJob() {
  // Construct request
  const request = {
    name: transcoderServiceClient.jobPath(projectId, location, jobId),
  };
  await transcoderServiceClient.deleteJob(request);
  console.log('Deleted job');
}

deleteJob();

PHP

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある PHP の設定手順を行ってください。 詳細については、Transcoder API PHP の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient;
use Google\Cloud\Video\Transcoder\V1\DeleteJobRequest;

/**
 * Deletes a Transcoder job.
 *
 * @param string $projectId The ID of your Google Cloud Platform project.
 * @param string $location The location of the job.
 * @param string $jobId The job ID.
 */
function delete_job($projectId, $location, $jobId)
{
    // Instantiate a client.
    $transcoderServiceClient = new TranscoderServiceClient();

    $formattedName = $transcoderServiceClient->jobName($projectId, $location, $jobId);
    $request = (new DeleteJobRequest())
        ->setName($formattedName);
    $transcoderServiceClient->deleteJob($request);

    print('Deleted job' . PHP_EOL);
}

Python

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある Python の設定手順を行ってください。 詳細については、Transcoder API Python の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


import argparse

from google.cloud.video.transcoder_v1.services.transcoder_service import (
    TranscoderServiceClient,
)

def delete_job(
    project_id: str,
    location: str,
    job_id: str,
) -> None:
    """Gets a job.

    Args:
        project_id: The GCP project ID.
        location: The location this job is in.
        job_id: The job ID."""

    client = TranscoderServiceClient()

    name = f"projects/{project_id}/locations/{location}/jobs/{job_id}"
    response = client.delete_job(name=name)
    print("Deleted job")
    return response

Ruby

このサンプルを試す前に、クライアント ライブラリを使用した Transcoder API クイックスタートにある Ruby の設定手順を行ってください。 詳細については、Transcoder API Ruby の API のリファレンス ドキュメントをご覧ください。

Transcoder API への認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

# project_id = "YOUR-GOOGLE-CLOUD-PROJECT"  # (e.g. "my-project")
# location   = "YOUR-JOB-LOCATION"  # (e.g. "us-central1")
# job_id     = "YOUR-JOB-ID"  # (e.g. "c82c295b-3f5a-47df-8562-938a89d40fd0")

# Require the Transcoder client library.
require "google/cloud/video/transcoder"

# Create a Transcoder client.
client = Google::Cloud::Video::Transcoder.transcoder_service

# Build the resource name of the job.
name = client.job_path project: project_id, location: location, job: job_id

# Delete the job.
client.delete_job name: name

# Print a success message.
puts "Deleted job"

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。