Créer un job à partir d'un modèle (asynchrone)
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Explique comment créer une tâche à partir d'un modèle.
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code examples in C#, Java, Node.js, and Python for creating a job from a template using the Dataflow API.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples demonstrate the \u003ccode\u003eCreateJobFromTemplate\u003c/code\u003e function call with examples of request initialization.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Dataflow requires setting up Application Default Credentials, with a link to instructions provided.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample is a template and requires modifications, such as setting correct values for request initialization and possibly regional endpoints.\u003c/p\u003e\n"],["\u003cp\u003eThe page references the Google Cloud sample browser for searching code samples for other google products.\u003c/p\u003e\n"]]],[],null,["# Create a job from a template (async)\n\nDemonstrates how to create a job from a template.\n\nCode sample\n-----------\n\n### C#\n\n\nTo authenticate to Dataflow, 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 using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.html;\n using System.Threading.Tasks;\n\n public sealed partial class GeneratedTemplatesServiceClientSnippets\n {\n /// \u003csummary\u003eSnippet for CreateJobFromTemplateAsync\u003c/summary\u003e\n /// \u003cremarks\u003e\n /// This snippet has been automatically generated and should be regarded as a code template only.\n /// It will require modifications to work:\n /// - It may require correct/in-range values for request initialization.\n /// - It may require specifying regional endpoints when creating the service client as shown in\n /// https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.\n /// \u003c/remarks\u003e\n public async Task CreateJobFromTemplateRequestObjectAsync()\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.TemplatesServiceClient.html templatesServiceClient = await https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.TemplatesServiceClient.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.TemplatesServiceClient.html#Google_Cloud_Dataflow_V1Beta3_TemplatesServiceClient_CreateAsync_System_Threading_CancellationToken_();\n // Initialize request argument(s)\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.CreateJobFromTemplateRequest.html request = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.CreateJobFromTemplateRequest.html\n {\n ProjectId = \"\",\n GcsPath = \"\",\n Parameters = { { \"\", \"\" }, },\n JobName = \"\",\n Environment = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.RuntimeEnvironment.html(),\n Location = \"\",\n };\n // Make the request\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.Job.html response = await templatesServiceClient.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.TemplatesServiceClient.html#Google_Cloud_Dataflow_V1Beta3_TemplatesServiceClient_CreateJobFromTemplateAsync_Google_Cloud_Dataflow_V1Beta3_CreateJobFromTemplateRequest_Google_Api_Gax_Grpc_CallSettings_(request);\n }\n }\n\n### Java\n\n\nTo authenticate to Dataflow, 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.api.core.https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html;\n import com.google.dataflow.v1beta3.CreateJobFromTemplateRequest;\n import com.google.dataflow.v1beta3.Job;\n import com.google.dataflow.v1beta3.RuntimeEnvironment;\n import com.google.dataflow.v1beta3.TemplatesServiceClient;\n import java.util.HashMap;\n\n public class AsyncCreateJobFromTemplate {\n\n public static void main(String[] args) throws Exception {\n asyncCreateJobFromTemplate();\n }\n\n public static void asyncCreateJobFromTemplate() throws Exception {\n // This snippet has been automatically generated and should be regarded as a code template only.\n // It will require modifications to work:\n // - It may require correct/in-range values for request initialization.\n // - It may require specifying regional endpoints when creating the service client as shown in\n // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library\n try (TemplatesServiceClient templatesServiceClient = TemplatesServiceClient.https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.SettableApiFuture.html#com_google_api_core_SettableApiFuture__V_create__()) {\n CreateJobFromTemplateRequest request =\n CreateJobFromTemplateRequest.newBuilder()\n .setProjectId(\"projectId-894832108\")\n .setJobName(\"jobName-1438096408\")\n .putAllParameters(new HashMap\u003cString, String\u003e())\n .setEnvironment(RuntimeEnvironment.newBuilder().build())\n .setLocation(\"location1901043637\")\n .build();\n ApiFuture\u003cJob\u003e future =\n templatesServiceClient.createJobFromTemplateCallable().futureCall(request);\n // Do something.\n Job response = future.get();\n }\n }\n }\n\n### Node.js\n\n\nTo authenticate to Dataflow, 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 * This snippet has been automatically generated and should be regarded as a code template only.\n * It will require modifications to work.\n * It may require correct/in-range values for request initialization.\n * TODO(developer): Uncomment these variables before running the sample.\n */\n /**\n * Required. The ID of the Cloud Platform project that the job belongs to.\n */\n // const projectId = 'abc123'\n /**\n * Required. The job name to use for the created job.\n */\n // const jobName = 'abc123'\n /**\n * Required. A Cloud Storage path to the template from which to\n * create the job.\n * Must be a valid Cloud Storage URL, beginning with `gs://`.\n */\n // const gcsPath = 'abc123'\n /**\n * The runtime parameters to pass to the job.\n */\n // const parameters = [1,2,3,4]\n /**\n * The runtime environment for the job.\n */\n // const environment = {}\n /**\n * The regional endpoint \n * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints) to\n * which to direct the request.\n */\n // const location = 'abc123'\n\n // Imports the Dataflow library\n const {TemplatesServiceClient} = require('https://cloud.google.com/nodejs/docs/reference/dataflow/latest/overview.html').v1beta3;\n\n // Instantiates a client\n const dataflowClient = new https://cloud.google.com/nodejs/docs/reference/dataflow/latest/overview.html();\n\n async function callCreateJobFromTemplate() {\n // Construct request\n const request = {\n };\n\n // Run request\n const response = await dataflowClient.createJobFromTemplate(request);\n console.log(response);\n }\n\n callCreateJobFromTemplate();\n\n### Python\n\n\nTo authenticate to Dataflow, 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 # This snippet has been automatically generated and should be regarded as a\n # code template only.\n # It will require modifications to work:\n # - It may require correct/in-range values for request initialization.\n # - It may require specifying regional endpoints when creating the service\n # client as shown in:\n # https://googleapis.dev/python/google-api-core/latest/client_options.html\n from google.cloud import https://cloud.google.com/python/docs/reference/dataflow/latest/\n\n\n async def sample_create_job_from_template():\n # Create a client\n client = https://cloud.google.com/python/docs/reference/dataflow/latest/.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.services.templates_service.TemplatesServiceAsyncClient.html()\n\n # Initialize request argument(s)\n request = https://cloud.google.com/python/docs/reference/dataflow/latest/.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.types.CreateJobFromTemplateRequest.html(\n gcs_path=\"gcs_path_value\",\n )\n\n # Make the request\n response = await client.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.services.templates_service.TemplatesServiceAsyncClient.html#google_cloud_dataflow_v1beta3_services_templates_service_TemplatesServiceAsyncClient_create_job_from_template(request=request)\n\n # Handle the response\n print(response)\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=dataflow)."]]