Skip to content

taskqueue: route PushQueues to Cloud Tasks v2 (GA) - #414

Open
riddhi-shivhare wants to merge 5 commits into
golang:masterfrom
riddhi-shivhare:taskqueue-v2-ga
Open

riddhi-shivhare wants to merge 5 commits into
golang:masterfrom
riddhi-shivhare:taskqueue-v2-ga

Conversation

@riddhi-shivhare

Copy link
Copy Markdown

When APPENGINE_USE_CLOUDTASK_PUSH_QUEUE is enabled, push queue
operations in both the root and v2 taskqueue packages are served by
the Cloud Tasks v2 API:

  • Add and AddMulti use CreateTask and BatchCreateTasks.
  • DeleteMulti uses BatchDeleteTasks.
  • QueueStats uses v2beta3 GetQueue, since queue stats are not part of
    the v2 API.
  • Transactional tasks are staged with the datastore transaction and
    dispatched after commit, with the existing 5-task limit.

Batch operations wait on the long-running operation and map
FailedRequests back to per-task errors in appengine.MultiError. If the
operation itself fails, the error is reported for every task in the
chunk. NOT_FOUND on create maps to UNKNOWN_QUEUE. Cloud Tasks clients
are created once and reused. When the variable is not set, behavior is
unchanged.

This re-adds the Cloud Tasks backend reverted in #409
and supersedes #412, which targeted the
taskqueue-migration-preview branch.

Adds cloud.google.com/go/cloudtasks v1.20.0. The go directive in
go.mod and v2/go.mod moves to 1.26.0, and CI moves to Go 1.26.x.
Unit tests are in taskqueue/cloudtask_test.go and
v2/taskqueue/cloudtask_test.go.

@riddhi-shivhare
riddhi-shivhare force-pushed the taskqueue-v2-ga branch 6 times, most recently from d9fb535 to 18bf8c2 Compare October 8, 2026 07:15
When APPENGINE_USE_CLOUDTASK_PUSH_QUEUE is enabled, push queue
operations in both the root and v2 taskqueue packages are served by the
Cloud Tasks v2 API:

- Add and AddMulti use CreateTask and BatchCreateTasks.
- DeleteMulti uses BatchDeleteTasks.
- QueueStats uses v2beta3 GetQueue, since queue stats are not part of
  the v2 API.
- Transactional tasks are staged with the datastore transaction and
  dispatched after commit, with the existing 5-task limit.

Each staged task is a root entity, so a transaction that adds tasks must
be cross-group (XG) unless it touches no other entity group. Staged
tasks get a generated name so that a repeated dispatch is rejected as
ALREADY_EXISTS. They are dispatched before RunInTransaction returns,
while the request's API ticket is still valid. Each staged entity is
locked in a datastore transaction before dispatch, so the post-commit
path and the /_ah/cloudtask/sweep cron handler do not dispatch it
concurrently. A failed commit, including a concurrent transaction,
releases the tasks staged for it. Failures are recorded on the entity
until it is marked FAILED after 5 attempts. Each sweep reads at most
500 entities of each status, and FAILED entities are deleted after 7
days. Staged entities use the kind, property names and payload form of
the Java and Python SDKs, a JSON object {"task": T} where T is the
proto3 JSON form of the v2 Task, so a sweeper in a service written in
any of them can dispatch them. Properties written by another SDK are
ignored, and entities staged in the binary form used by earlier
versions are still dispatched.

Batch operations read the synchronous operation result and map
FailedRequests in the operation metadata back to per-task errors in
appengine.MultiError. NOT_FOUND on create maps to UNKNOWN_QUEUE. A Host
header that is a hostname of the app sets the task's service, version
and instance. Host, X-Google-* and X-AppEngine-* headers are not sent,
since Cloud Tasks sets the App Engine headers itself. AddMulti and
DeleteMulti with no tasks return without calling any API. Cloud Tasks
clients are created once and reused.

Adds cloud.google.com/go/cloudtasks v1.20.0 and unit tests in
taskqueue/cloudtask_test.go, taskqueue/cloudtask_transactional_test.go
and their v2 copies.

@gajjarc gajjarc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, lets wait for the tiny launch doc approval and have the public doc cl ready. Then we can safely merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants