Membuat tugas secara asinkron
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menunjukkan cara membuat tugas secara asinkron.
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code examples in C#, Java, Node.js, and Python that demonstrate how to asynchronously create a job using the Dataflow API.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample requires Application Default Credentials to be set up for authentication with Dataflow, and a link is provided for more information on the setup.\u003c/p\u003e\n"],["\u003cp\u003eThe examples show the basic structure of creating a \u003ccode\u003eCreateJobRequest\u003c/code\u003e and then calling the \u003ccode\u003ecreateJob\u003c/code\u003e or \u003ccode\u003eCreateJobAsync\u003c/code\u003e method, which are part of the \u003ccode\u003eJobsV1Beta3Client\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code is a template and may require modifications, such as providing correct values for project ID, job details, view, location and other parameters.\u003c/p\u003e\n"],["\u003cp\u003eThe content suggests that users can explore the Google Cloud sample browser for additional code samples related to Dataflow and other products.\u003c/p\u003e\n"]]],[],null,["# Create a job asynchronously\n\nDemonstrates how to create a job asynchronously.\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 GeneratedJobsV1Beta3ClientSnippets\n {\n /// \u003csummary\u003eSnippet for CreateJobAsync\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 CreateJobRequestObjectAsync()\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html jobsV1Beta3Client = await https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html#Google_Cloud_Dataflow_V1Beta3_JobsV1Beta3Client_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.CreateJobRequest.html request = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.CreateJobRequest.html\n {\n ProjectId = \"\",\n Job = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.Job.html(),\n View = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobView.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobView.html#Google_Cloud_Dataflow_V1Beta3_JobView_Unknown,\n ReplaceJobId = \"\",\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 jobsV1Beta3Client.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html#Google_Cloud_Dataflow_V1Beta3_JobsV1Beta3Client_CreateJobAsync_Google_Cloud_Dataflow_V1Beta3_CreateJobRequest_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.CreateJobRequest;\n import com.google.dataflow.v1beta3.Job;\n import com.google.dataflow.v1beta3.JobView;\n import com.google.dataflow.v1beta3.JobsV1Beta3Client;\n\n public class AsyncCreateJob {\n\n public static void main(String[] args) throws Exception {\n asyncCreateJob();\n }\n\n public static void asyncCreateJob() 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 (JobsV1Beta3Client jobsV1Beta3Client = JobsV1Beta3Client.https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.SettableApiFuture.html#com_google_api_core_SettableApiFuture__V_create__()) {\n CreateJobRequest request =\n CreateJobRequest.newBuilder()\n .setProjectId(\"projectId-894832108\")\n .setJob(Job.newBuilder().build())\n .setView(JobView.forNumber(0))\n .setReplaceJobId(\"replaceJobId441554788\")\n .setLocation(\"location1901043637\")\n .build();\n ApiFuture\u003cJob\u003e future = jobsV1Beta3Client.createJobCallable().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 * The ID of the Cloud Platform project that the job belongs to.\n */\n // const projectId = 'abc123'\n /**\n * The job to create.\n */\n // const job = {}\n /**\n * The level of information requested in response.\n */\n // const view = {}\n /**\n * The regional endpoint \n * (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints) that\n * contains this job.\n */\n // const location = 'abc123'\n\n // Imports the Dataflow library\n const {JobsV1Beta3Client} = 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 callCreateJob() {\n // Construct request\n const request = {\n };\n\n // Run request\n const response = await dataflowClient.createJob(request);\n console.log(response);\n }\n\n callCreateJob();\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():\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.jobs_v1_beta3.JobsV1Beta3AsyncClient.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.CreateJobRequest.html(\n )\n\n # Make the request\n response = await client.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.JobsV1Beta3AsyncClient.html#google_cloud_dataflow_v1beta3_services_jobs_v1_beta3_JobsV1Beta3AsyncClient_create_job(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)."]]