Membuat tugas dari template (asinkron)

Menunjukkan cara membuat tugas dari template.

Contoh kode

C#

Untuk melakukan autentikasi ke Dataflow, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

using Google.Cloud.Dataflow.V1Beta3;
using System.Threading.Tasks;

public sealed partial class GeneratedTemplatesServiceClientSnippets
{
    /// <summary>Snippet for CreateJobFromTemplateAsync</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public async Task CreateJobFromTemplateRequestObjectAsync()
    {
        // Create client
        TemplatesServiceClient templatesServiceClient = await TemplatesServiceClient.CreateAsync();
        // Initialize request argument(s)
        CreateJobFromTemplateRequest request = new CreateJobFromTemplateRequest
        {
            ProjectId = "",
            GcsPath = "",
            Parameters = { { "", "" }, },
            JobName = "",
            Environment = new RuntimeEnvironment(),
            Location = "",
        };
        // Make the request
        Job response = await templatesServiceClient.CreateJobFromTemplateAsync(request);
    }
}

Java

Untuk melakukan autentikasi ke Dataflow, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import com.google.api.core.ApiFuture;
import com.google.dataflow.v1beta3.CreateJobFromTemplateRequest;
import com.google.dataflow.v1beta3.Job;
import com.google.dataflow.v1beta3.RuntimeEnvironment;
import com.google.dataflow.v1beta3.TemplatesServiceClient;
import java.util.HashMap;

public class AsyncCreateJobFromTemplate {

  public static void main(String[] args) throws Exception {
    asyncCreateJobFromTemplate();
  }

  public static void asyncCreateJobFromTemplate() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (TemplatesServiceClient templatesServiceClient = TemplatesServiceClient.create()) {
      CreateJobFromTemplateRequest request =
          CreateJobFromTemplateRequest.newBuilder()
              .setProjectId("projectId-894832108")
              .setJobName("jobName-1438096408")
              .putAllParameters(new HashMap<String, String>())
              .setEnvironment(RuntimeEnvironment.newBuilder().build())
              .setLocation("location1901043637")
              .build();
      ApiFuture<Job> future =
          templatesServiceClient.createJobFromTemplateCallable().futureCall(request);
      // Do something.
      Job response = future.get();
    }
  }
}

Node.js

Untuk melakukan autentikasi ke Dataflow, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The ID of the Cloud Platform project that the job belongs to.
 */
// const projectId = 'abc123'
/**
 *  Required. The job name to use for the created job.
 */
// const jobName = 'abc123'
/**
 *  Required. A Cloud Storage path to the template from which to
 *  create the job.
 *  Must be a valid Cloud Storage URL, beginning with `gs://`.
 */
// const gcsPath = 'abc123'
/**
 *  The runtime parameters to pass to the job.
 */
// const parameters = [1,2,3,4]
/**
 *  The runtime environment for the job.
 */
// const environment = {}
/**
 *  The regional endpoint 
 *  (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints) to
 *  which to direct the request.
 */
// const location = 'abc123'

// Imports the Dataflow library
const {TemplatesServiceClient} = require('@google-cloud/dataflow').v1beta3;

// Instantiates a client
const dataflowClient = new TemplatesServiceClient();

async function callCreateJobFromTemplate() {
  // Construct request
  const request = {
  };

  // Run request
  const response = await dataflowClient.createJobFromTemplate(request);
  console.log(response);
}

callCreateJobFromTemplate();

Python

Untuk melakukan autentikasi ke Dataflow, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataflow_v1beta3


async def sample_create_job_from_template():
    # Create a client
    client = dataflow_v1beta3.TemplatesServiceAsyncClient()

    # Initialize request argument(s)
    request = dataflow_v1beta3.CreateJobFromTemplateRequest(
        gcs_path="gcs_path_value",
    )

    # Make the request
    response = await client.create_job_from_template(request=request)

    # Handle the response
    print(response)

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud.