[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003ePull queues in the App Engine standard environment require worker services to actively request tasks, in contrast to push queues where tasks are automatically delivered.\u003c/p\u003e\n"],["\u003cp\u003eWorkers in pull queues operate on tasks with a lease, a designated period of exclusive access, after which the task can be processed by another worker if not completed.\u003c/p\u003e\n"],["\u003cp\u003ePull queues enable task batching through the use of tags, allowing workers to retrieve multiple related tasks simultaneously.\u003c/p\u003e\n"],["\u003cp\u003eUnlike push queues, pull queue implementations necessitate manual scaling of workers and explicit task deletion by the worker service after completion to avoid resource waste or errors.\u003c/p\u003e\n"],["\u003cp\u003eThe workflow for pull queues involves creating a queue via \u003ccode\u003equeue.yaml\u003c/code\u003e, adding tasks, leasing tasks to a worker, processing, potentially modifying the lease duration, and finally, deleting the completed task.\u003c/p\u003e\n"]]],[],null,["# Using Pull Queues in Go\n\nThis page provides an overview of pull queues in the App Engine\nstandard environment.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| go\n| /services/access). If you are updating to the App Engine Go 1.12+ runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/go-differences) to learn about your migration options for legacy bundled services.\n\nIn *push* queues tasks are delivered to a worker service\nbased on the queue's configuration. In *pull* queues the worker service must *ask*\nthe queue for tasks. The queue responds by allowing that worker unique access\nto process the task for a specified period of time, which is called a *lease*.\n\nUsing pull queues, you can also group related tasks using tags and then configure your\nworker to pull multiple tasks with a certain tag all at once. This process is\ncalled *batching*.\n\nIf a worker cannot process a task before its lease expires, it can either renew the\nlease or let it expire, at which point another worker can acquire it. Once the\nwork associated with a task is complete, the worker must delete it.\n\nUsing pull queues requires your code to handle some functions that are automated\nin push queues:\n\nScaling your workers\n: Your code needs to scale the number of workers based on\n processing volume. If your code does not handle scaling, you risk\n wasting computing resources if there are no tasks to process; you also risk\n latency if you have too many tasks to process.\n\nDeleting the tasks\n: Your code also needs to explicitly delete tasks after processing.\n In push queues, App Engine deletes the tasks for you. If your worker does\n not delete pull queue tasks after processing, another worker will re-process\n the task. This wastes computing resources and risks errors if tasks are\n not [idempotent](https://wikipedia.org/wiki/Idempotence).\n\nPull queues in the App Engine standard environment are created by setting a property in a\nconfiguration file called `queue.yaml`.\n\nPull queue workflow\n-------------------\n\nWorkers that process tasks from pull queues must be defined within a service that runs\nin the App Engine standard environment.\n\nThe workflow is as follows:\n\n1. You [create a pull queue](/appengine/docs/legacy/standard/go111/taskqueue/pull/creating-pull-queues), using `queue.yaml`.\n2. You [create tasks](/appengine/docs/legacy/standard/go111/taskqueue/pull/creating-tasks) and add them to the queue.\n3. The worker you have created [leases the task](/appengine/docs/legacy/standard/go111/taskqueue/pull/leasing-pull-tasks), using [TaskQueue.](/appengine/docs/legacy/standard/go111/taskqueue/reference)\n4. App Engine sends task data to the worker in the lease response.\n5. The worker processes the task. If the task fails to execute before the lease expires, the worker can modify the lease duration. If the lease expires, the task will be available to be leased to another worker.\n6. After a task is processed successfully, the [worker deletes it](/appengine/docs/legacy/standard/go111/taskqueue/pull/leasing-pull-tasks#deleting-tasks).\n\nWhat's next\n-----------\n\n- Learn how to [create pull queues](/appengine/docs/legacy/standard/go111/taskqueue/pull/creating-pull-queues)."]]