작업 상태 가져오기

특정 트랜스코딩 작업의 작업 상태를 가져옵니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

C#

이 샘플을 사용해 보기 전에 Transcoder API 빠른 시작: 클라이언트 라이브러리 사용C# 설정 안내를 따르세요. 자세한 내용은 Transcoder API C# API 참조 문서를 확인하세요.

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


using Google.Cloud.Video.Transcoder.V1;

public class GetJobStateSample
{
    public Job.Types.ProcessingState GetJobState(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.
        Job job = client.GetJob(jobName);

        // Return the result.
        return job.State;
    }
}

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"
)

// getJobState gets the state for a previously-created job. See
// https://cloud.google.com/transcoder/docs/how-to/jobs#check_job_status for
// more information.
func getJobState(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.GetJobRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/jobs/%s", projectID, location, jobID),
	}

	response, err := client.GetJob(ctx, req)
	if err != nil {
		return fmt.Errorf("GetJob: %w", err)
	}
	fmt.Fprintf(w, "Job state: %v\n----\nJob failure reason:%v\n", response.State, response.Error)
	return nil
}

Java

이 샘플을 사용해 보기 전에 Transcoder API 빠른 시작: 클라이언트 라이브러리 사용Java 설정 안내를 따르세요. 자세한 내용은 Transcoder API Java API 참조 문서를 확인하세요.

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


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

public class GetJobState {

  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";

    getJobState(projectId, location, jobId);
  }

  // Gets the state of a job.
  public static void getJobState(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();
      GetJobRequest getJobRequest = GetJobRequest.newBuilder().setName(jobName.toString()).build();

      // Send the get job request and process the response.
      Job job = transcoderServiceClient.getJob(getJobRequest);
      System.out.println("Job state: " + job.getState());
    }
  }
}

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 getJob() {
  // Construct request
  const request = {
    name: transcoderServiceClient.jobPath(projectId, location, jobId),
  };
  const [response] = await transcoderServiceClient.getJob(request);
  console.log(`Job state: ${response.state}`);
}

getJob();

PHP

이 샘플을 사용해 보기 전에 Transcoder API 빠른 시작: 클라이언트 라이브러리 사용PHP 설정 안내를 따르세요. 자세한 내용은 Transcoder API PHP API 참조 문서를 확인하세요.

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

use Google\Cloud\Video\Transcoder\V1\Client\TranscoderServiceClient;
use Google\Cloud\Video\Transcoder\V1\GetJobRequest;
use Google\Cloud\Video\Transcoder\V1\Job;

/**
 * Gets a Transcoder job's state.
 *
 * @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 get_job_state($projectId, $location, $jobId)
{
    // Instantiate a client.
    $transcoderServiceClient = new TranscoderServiceClient();

    $formattedName = $transcoderServiceClient->jobName($projectId, $location, $jobId);
    $request = (new GetJobRequest())
        ->setName($formattedName);
    $job = $transcoderServiceClient->getJob($request);

    // Print job state.
    printf('Job state: %s' . PHP_EOL, Job\ProcessingState::name($job->getState()));
}

Python

이 샘플을 사용해 보기 전에 Transcoder API 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 Transcoder API Python API 참조 문서를 확인하세요.

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


import argparse

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

def get_job_state(
    project_id: str,
    location: str,
    job_id: str,
) -> transcoder_v1.types.resources.Job:
    """Gets a job's state.

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

    Returns:
        The job resource.
    """

    client = TranscoderServiceClient()

    name = f"projects/{project_id}/locations/{location}/jobs/{job_id}"
    response = client.get_job(name=name)

    print(f"Job state: {str(response.state.name)}")
    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

# Get the job.
job = client.get_job name: name

# Print the job state.
puts "Job state: #{job.state}"

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.