Migrate push queues to Cloud Tasks by upgrading to the latest SDK (Java)

Before you upgrade to the latest App Engine services SDK version, review the migration overview.

You can migrate to Cloud Tasks automatically by updating your App Engine services SDK to the latest version. After you upgrade, the SDK automatically redirects PushQueue calls to the Cloud Tasks frontend APIs for you. Cloud Tasks retains your existing task queues and tasks, so no additional migration is required.

Behind the scenes, the updated SDK uses the Cloud Tasks APIs to maintain feature parity with Task Queues features, the SDK supports the following:

  • Batch task creation: The SDK uses batch APIs to support adding up to 100 tasks in a single call.
  • Batch task deletion: The SDK uses batch APIs to support deleting up to 1,000 tasks in a single call.
  • Task-level retries: The SDK supports task-specific retry configurations.
  • Transactional tasks: The SDK enqueues tasks within Datastore transactions. To maintain reliability, either create or modify the cron.yaml file.

Pricing and quotas

Migrating your push queues to Cloud Tasks might affect the pricing and quotas for your app.

Pricing

Review the Cloud Tasks pricing to estimate your monthly cost before migrating.

Similar to Task Queues, sending requests to your App Engine app with a Cloud Tasks push target is free. However, unlike Task Queues, Cloud Tasks charges for operations performed, such as creating, deleting, or managing tasks. This might lead to higher overall monthly cost compared to the complimentary App Engine Task Queue.

If you migrate by upgrading the App Engine services SDK and your application enqueues transactional tasks within Datastore transactions, each enqueued task incurs 3 writes, 2 reads, and 1 delete in Datastore in addition to standard Cloud Tasks API billing.

Quotas

Cloud Tasks requests also count towards your App Engine requests quotas.

Like Task Queues, Cloud Tasks has service-specific quotas. Migrating to Cloud Tasks will likely change your quotas.

Optimize request latency

Because the updated SDK sends requests directly to the Cloud Tasks API, enqueuing or deleting individual tasks sequentially can increase request latency compared to the legacy Task Queues service. To minimize latency:

  • Batch multiple tasks into a single call: Group tasks into batch add calls (up to 100 tasks per call) or batch delete calls (up to 1,000 tasks per call) instead of enqueuing or deleting tasks one by one in a loop.
  • Use asynchronous API calls: Use non-blocking methods such as addAsync() and deleteTaskAsync() so task operations don't block request handling.

Before you begin

Complete the following steps before migrating push queues to Cloud Tasks:

  1. Make sure that you have access to the App Engine source code.

  2. Enable the Cloud Tasks and Cloud Scheduler APIs:

    Enable APIs

  3. To ensure that the App Engine service account has the necessary permissions to let the SDK dispatch tasks to the Cloud Tasks API, ask your administrator to grant the Cloud Tasks Enqueuer (roles/cloudtasks.enqueuer) IAM role on the project.

Update the App Engine services SDK

  1. Ensure your application uses the latest version of the App Engine services SDK.

    In your pom.xml, update the App Engine services SDK to version 5.2.0 or higher.

    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>5.2.0</version>
    </dependency>
  2. Enable Cloud Tasks routing

    runtime: java25
    service: my-service-b
    
    env_variables:
      APPENGINE_USE_CLOUDTASK_PUSH_QUEUE: "true"
    

    Update the App Engine SDK dependency in your pom.xml to version 5.2.0 or higher.

    If your app uses an XML configuration (appengine-web.xml):

    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
      <service>my-java-service-b</service>
      <runtime>java25</runtime>
      <env-variables>
        <env-var name="APPENGINE_USE_CLOUDTASK_PUSH_QUEUE" value="true" />
      </env-variables>
    </appengine-web-app>
    
  3. Deploy your app:

    gcloud app deploy
    
  4. To verify that your app is using Cloud Tasks, go to the Cloud Tasks page in the Google Cloud console.

Configure transactional tasks (optional)

If your app enqueues tasks within Datastore transactions, the SDK relies on an internal cron job to ensure that any tasks that fail to enqueue during the datastore commit are eventually processed.

To handle push queue transactional tasks, create or update your cron.yaml file to periodically call the internal processor. For example:

cron:
- description: "Process push queue transactional tasks"
  url: /_ah/cloudtask/sweep
  schedule: every 30 minutes # Change this based on the usage pattern

Add a URL mapping in your web.xml file for com.google.apphosting.utils.servlet.SweeperServlet, or com.google.apphosting.utils.servlet.jakarta.SweeperServlet for Java 17 and later Jakarta EE runtimes.

<servlet>
 <servlet-name>cloudtask_sweep</servlet-name>
 <servlet-class>com.google.apphosting.utils.servlet.SweeperServlet</servlet-class>
</servlet>
<servlet-mapping>
 <servlet-name>cloudtask_sweep</servlet-name>
 <url-pattern>/_ah/cloudtask/sweep</url-pattern>
</servlet-mapping>

What's next