A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/appengine/docs/legacy/standard/java/taskqueue/pull/leasing-pull-tasks below:

Leasing Pull Tasks | App Engine standard environment for Java 8

Leasing Pull Tasks

Stay organized with collections Save and categorize content based on your preferences.

Once tasks are in a pull queue, a worker can lease them. After the tasks are processed the worker must delete them.

This API is supported for first-generation runtimes and can be used when upgrading to corresponding second-generation runtimes. If you are updating to the App Engine Java 11/17 runtime, refer to the migration guide to learn about your migration options for legacy bundled services. Before you begin Important context Leasing tasks

After the tasks are in the queue, a worker can lease one or more of them using the leaseTasks() method. There may be a short delay before tasks recently added using add() become available via leaseTasks().

When you request a lease, you specify the number of tasks to lease (up to a maximum of 1,000 tasks) and the duration of the lease in seconds (up to a maximum of one week). The lease duration needs to be long enough to ensure that the slowest task will have time to finish before the lease period expires. You can modify a task lease using modifyTaskLease().

Leasing a task makes it unavailable for processing by another worker, and it remains unavailable until the lease expires.

Note: leaseTasks() operates only on pull queues. If you attempt to lease tasks added in a push queue, App Engine throws an exception.

The following code sample leases tasks from the queue pull-queue for one hour:

Batching with task tags

Beta

This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the Service Specific Terms. Pre-GA products and features are available "as is" and might have limited support. For more information, see the launch stage descriptions.

Not all tasks are alike; your code can "tag" tasks and then choose tasks to lease by tag. The tag acts as a filter.

Then lease the filtered tasks:

Regulating polling rates

Workers that poll the queue for tasks to lease should detect whether they are attempting to lease tasks faster than the queue can supply them. If this failure occurs, the following exceptions from leaseTasks() can be generated:


Your code must catch these exceptions, back off from calling leaseTasks(), and then try again later. To avoid this problem, consider setting a higher RPC deadline when calling leaseTasks(). You should also back off when a lease request returns an empty list of tasks.

If you generate more than 10 LeaseTasks requests per queue per second, only the first 10 requests will return results. If requests exceed this limit, OK is returned with zero results.

Monitoring tasks in the Google Cloud console

To view information about all the tasks and queues in your application:

  1. Open the Cloud Tasks page in the Google Cloud console and look for the Pull value in column Type.

    Go to Cloud Tasks

  2. Click on the name of the queue in which you are interested, opening the queue details page. It displays all of the tasks in the selected queue.

Deleting tasks

Once a worker completes a task, it needs to delete the task from the queue. If you see tasks remaining in a queue after a worker finishes processing them, it is likely that the worker failed; in this case, the tasks will be processed by another worker.

You can delete an individual task or a list of tasks using deleteTask(). You must know the name of a task in order to delete it. You can find task names in the Task object returned by leaseTasks().

The following code sample demonstrates how to delete a task from a queue:

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Workers can lease tasks from a pull queue using the `leaseTasks()` method, which makes the task temporarily unavailable to other workers."],["Tasks can be tagged, and workers can then lease tasks based on these tags using `leaseTasksByTag()`, allowing for filtered task processing."],["Workers must delete tasks from the queue using `deleteTask()` after they have completed processing them; failure to do so may result in the task being picked up by another worker."],["Polling rates for leasing tasks should be regulated to avoid exceptions like `TransientFailureException` or `ApiDeadlineExceededException`, and if the polling is too frequent, only the first 10 requests will return results."],["The Cloud Console allows for the monitoring of tasks and queues, enabling users to view information about tasks and queues, as well as look for the *Pull* type within the queue."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4