Lancer un modèle (asynchrone)

Explique comment lancer un modèle.

Exemple de code

C#

Pour vous authentifier auprès de Dataflow, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez la page Configurer l'authentification pour un environnement de développement local.

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

public sealed partial class GeneratedTemplatesServiceClientSnippets
{
    /// <summary>Snippet for LaunchTemplateAsync</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 LaunchTemplateRequestObjectAsync()
    {
        // Create client
        TemplatesServiceClient templatesServiceClient = await TemplatesServiceClient.CreateAsync();
        // Initialize request argument(s)
        LaunchTemplateRequest request = new LaunchTemplateRequest
        {
            ProjectId = "",
            ValidateOnly = false,
            GcsPath = "",
            LaunchParameters = new LaunchTemplateParameters(),
            Location = "",
        };
        // Make the request
        LaunchTemplateResponse response = await templatesServiceClient.LaunchTemplateAsync(request);
    }
}

Java

Pour vous authentifier auprès de Dataflow, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez la page Configurer l'authentification pour un environnement de développement local.

import com.google.api.core.ApiFuture;
import com.google.dataflow.v1beta3.LaunchTemplateParameters;
import com.google.dataflow.v1beta3.LaunchTemplateRequest;
import com.google.dataflow.v1beta3.LaunchTemplateResponse;
import com.google.dataflow.v1beta3.TemplatesServiceClient;

public class AsyncLaunchTemplate {

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

  public static void asyncLaunchTemplate() 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()) {
      LaunchTemplateRequest request =
          LaunchTemplateRequest.newBuilder()
              .setProjectId("projectId-894832108")
              .setValidateOnly(true)
              .setLaunchParameters(LaunchTemplateParameters.newBuilder().build())
              .setLocation("location1901043637")
              .build();
      ApiFuture<LaunchTemplateResponse> future =
          templatesServiceClient.launchTemplateCallable().futureCall(request);
      // Do something.
      LaunchTemplateResponse response = future.get();
    }
  }
}

Node.js

Pour vous authentifier auprès de Dataflow, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez la page Configurer l'authentification pour un environnement de développement local.

/**
 * 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'
/**
 *  If true, the request is validated but not actually executed.
 *  Defaults to false.
 */
// const validateOnly = true
/**
 *  A Cloud Storage path to the template from which to create
 *  the job.
 *  Must be valid Cloud Storage URL, beginning with 'gs://'.
 */
// const gcsPath = 'abc123'
/**
 *  Params for launching a dynamic template.
 */
// const dynamicTemplate = {}
/**
 *  The parameters of the template to launch. This should be part of the
 *  body of the POST request.
 */
// const launchParameters = {}
/**
 *  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 callLaunchTemplate() {
  // Construct request
  const request = {
  };

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

callLaunchTemplate();

Python

Pour vous authentifier auprès de Dataflow, configurez le service Identifiants par défaut de l'application. Pour en savoir plus, consultez la page Configurer l'authentification pour un environnement de développement local.

# 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_launch_template():
    # Create a client
    client = dataflow_v1beta3.TemplatesServiceAsyncClient()

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

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

    # Handle the response
    print(response)

Étapes suivantes

Pour rechercher et filtrer des exemples de code pour d'autres produits Google Cloud, consultez l'explorateur d'exemples Google Cloud.