Mengantrekan eksekusi alur kerja menggunakan Cloud Tasks
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Anda dapat menggunakan Cloud Tasks untuk mengantrekan alur kerja dan mengeksekusinya secara asinkron.
Cloud Tasks menawarkan kontrol berikut:
Menjadwalkan waktu pengiriman tertentu
Mengelola rasio penayangan
Mengonfigurasi perilaku percobaan ulang
Mengakses dan mengelola tugas individual dalam antrean
Mengaktifkan penghapusan duplikat tugas
Kontrol ini dapat berguna, misalnya, untuk mengelola permintaan yang memicu alur kerja dan yang secara tidak terduga dapat melampaui batas Workflows. Dengan
mengonfigurasi antrean Cloud Tasks dengan batas frekuensi dan percobaan ulang,
Anda dapat memastikan bahwa semua permintaan tersebut menghasilkan eksekusi alur kerja.
Anda harus mendasarkan batas frekuensi pada batas Workflows
untuk permintaan penulisan Execution API. Jika
perlu, Anda dapat meminta penyesuaian pada sebagian besar kuota di konsol Google Cloud .
Cari tahu lebih lanjut
penyesuaian kuota.
Cloud Tasks didesain untuk memberikan pengiriman "setidaknya satu kali";
namun, Workflows tidak memastikan pemrosesan tepat satu kali untuk
permintaan duplikat dari Cloud Tasks.
Anda dapat menghilangkan penundaan eksekusi dan memaksimalkan throughput dengan mengaktifkan
penumpukan eksekusi di Alur Kerja. Eksekusi yang tertunda akan otomatis berjalan segera setelah kuota serentak eksekusi tersedia. Untuk
mengetahui informasi selengkapnya, lihat
Mengelola backlog eksekusi.
Sebelum memulai
Jika Anda belum memiliki alur kerja yang ingin dimasukkan dalam antrean,
buat alur kerja.
Ganti SERVICE_ACCOUNT_NAME dengan nama yang terdiri dari 6 hingga 30 karakter. Dapat berisi karakter alfanumerik huruf kecil dan tanda hubung. Setelah membuat akun layanan, Anda tidak dapat mengubah namanya.
QUEUE_ID: ID yang Anda tetapkan ke antrean
Cloud Tasks; misalnya, my-queue.
PROJECT_NAME: nama project Google Cloud
Anda.
REGION_NAME: region tempat alur kerja Anda berada, seperti us-central1.
WORKFLOW_NAME: nama alur kerja yang ingin Anda
buatkan tugas.
DOUBLE_ESCAPED_JSON_STRING: encoding JSON dari
argumen apa pun yang Anda teruskan. Tanda kutip ganda di dalam
string yang dikutip di-escape menggunakan garis miring terbalik (\). Misalnya:
--body-content="{\"argument\": \"{\\\"foo\\\": \\\"bar\\\"}\"}"
SERVICE_ACCOUNT_NAME: nama akun layanan yang Anda buat sebelumnya.
Tugas Anda dibuat dan ditambahkan ke antrean Cloud Tasks.
Tugas tetap ada dalam antrean hingga eksekusi alur kerja dimulai dan
menampilkan kode status HTTP 2xx, yang pada saat itu Cloud Tasks
menganggap tugas selesai.
[[["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"]],["Terakhir diperbarui pada 2025-09-03 UTC."],[],[],null,["# Queue workflow executions using Cloud Tasks\n\nYou can use Cloud Tasks to queue a workflow and execute it\nasynchronously.\n\nCloud Tasks offers the following controls:\n\n- Schedule specific delivery times\n- Manage delivery rates\n- Configure retry behavior\n- Access and manage individual tasks in a queue\n- Enable task deduplication\n\nThese controls can be useful, for example, to manage requests that trigger a\nworkflow and that could unexpectedly exceed Workflows limits. By\nconfiguring a Cloud Tasks queue with rate limits and retries,\nyou can ensure that all such requests result in workflow executions.\n\nFor more information, see\n[Understand Cloud Tasks](/tasks/docs/dual-overview).\n\nNote the following:\n\n- You should base the rate limit on the Workflows limit\n for [Execution API write requests](/workflows/quotas#quotas). If\n necessary, you can request an adjustment to most quotas in the Google Cloud console.\n Find out more about\n [quota adjustments](/docs/quotas/overview#about_increase_requests).\n\n- Cloud Tasks is designed to provide \"at least once\" delivery;\n however, Workflows doesn't ensure exactly-once processing of\n duplicate requests from Cloud Tasks.\n\n- You can remove execution delays and maximize throughput by enabling\n execution backlogging in Workflows. Backlogged executions\n automatically run as soon as execution concurrency quota becomes available. For\n more information, see\n [Manage execution backlogging](/workflows/docs/executing-workflow#manage_execution_backlogging).\n\nBefore you begin\n----------------\n\n1. If you don't already have a workflow that you would like to queue, [create one](/workflows/docs/creating-updating-workflow#creating_a_workflow).\n2.\n\n\n Enable the Cloud Tasks API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudtasks.googleapis.com)\n\nQueue a task to execute a workflow\n----------------------------------\n\n1. Create a [service account](/workflows/docs/authentication)\n so that Cloud Tasks can make requests to the Workflows API:\n\n ```bash\n gcloud iam service-accounts create SERVICE_ACCOUNT_NAME\n ```\n\n Replace \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e with a name that is\n between 6 and 30 characters. It can contain lowercase alphanumeric characters\n and dashes. After you create a service account, you cannot change its name.\n2. To allow the principal that will run your Cloud Tasks\n commands the ability to act as an Identity and Access Management (IAM) service\n account,\n [grant a role that allows the principal to impersonate the service account](/iam/docs/service-account-permissions#roles).\n\n3. Grant your new service account the\n [workflows.invoker](/workflows/docs/access-control#roles) role so that the\n account has permission to trigger your workflow:\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_NAME \\\n --member serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_NAME.iam.gserviceaccount.com \\\n --role roles/workflows.invoker\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e: the name of your Google Cloud project.\n - \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e: the name of the service account that you previously created.\n4. If you don't already have a Cloud Tasks queue,\n [create one](/tasks/docs/creating-queues).\n\n5. Create a task that targets your workflow's HTTP endpoint, using the\n service account you previously created to authenticate:\n\n ```bash\n gcloud tasks create-http-task \\\n --queue=\"\u003cvar translate=\"no\"\u003eQUEUE_ID\u003c/var\u003e\" \\\n --url=\"https://workflowexecutions.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e/workflows/\u003cvar translate=\"no\"\u003eWORKFLOW_NAME\u003c/var\u003e/executions\" \\\n --body-content=\"{\\\"argument\\\": \\\"\u003cvar translate=\"no\"\u003eDOUBLE_ESCAPED_JSON_STRING\u003c/var\u003e\\\"}\" \\\n --oauth-service-account-email=\"\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e@\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e.iam.gserviceaccount.com\"\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eQUEUE_ID\u003c/var\u003e: the identifier you assigned to your Cloud Tasks queue; for example, `my-queue`.\n - \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e: the name of your Google Cloud project.\n - \u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e: the region your workflow is in, such as `us-central1`.\n - \u003cvar translate=\"no\"\u003eWORKFLOW_NAME\u003c/var\u003e: the name of the workflow you want to create a task for.\n - \u003cvar translate=\"no\"\u003eDOUBLE_ESCAPED_JSON_STRING\u003c/var\u003e: a JSON encoding of any arguments you are passing. The double quotation marks inside the quoted string are escaped using backslashes (\\\\). For example: `--body-content=\"{\\\"argument\\\": \\\"{\\\\\\\"foo\\\\\\\": \\\\\\\"bar\\\\\\\"}\\\"}\"`\n - \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e: the name of the service account that you previously created.\n\n Your task is created and added to your Cloud Tasks queue.\n The task persists in the queue until the workflow execution starts and\n returns an HTTP `2xx` status code, at which point Cloud Tasks\n considers the task complete.\n | **Note:** Cloud Tasks retries failures according to the [retry settings](/tasks/docs/reference/rpc/google.cloud.tasks.v2#retryconfig), and does not monitor long-running operations. (See how to [configure the maximum duration](/tasks/docs/reference/rpc/google.cloud.tasks.v2#task).) Issues starting the workflow execution (for example, an `HTTP 429` when there are too many requests) can be handled by Cloud Tasks but workflow execution failures are not retried. Each execution of a workflow incurs costs, as detailed in [Workflows pricing](/workflows/pricing).\n\nWhat's next\n-----------\n\n- [Tutorial: Use a Cloud Tasks queue to buffer your workflow executions](/workflows/docs/tutorials/buffer-workflows-executions)\n- [Manage queues and tasks](/tasks/docs/deleting-appengine-queues-and-tasks)\n- [Manage execution backlogging](/workflows/docs/executing-workflow#manage_execution_backlogging)\n- [Pass runtime arguments in an execution request](/workflows/docs/passing-runtime-arguments)"]]