taskqueue: route PushQueues to Cloud Tasks v2 (GA) (#414)
* taskqueue: route push queues to Cloud Tasks v2 (GA)
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.
* fix(taskqueue): reject AddMulti >100 and DeleteMulti >1000 instead of chunking
* fix(taskqueue): verify op.Done() before op.Wait() on batch operations
* test(taskqueue): verify done=false batch operations fail without polling
* Stage and sweep _AE_PendingCloudTask in the default empty namespace
* test: fix pre-existing Go 1.26 vet and allocation failures
Bumping go.mod and CI workflows to Go 1.26 (required by
cloud.google.com/go/cloudtasks v1.20.0) surfaced two pre-existing
issues in untouched test files:
- Use %v instead of %q when formatting *memcache.Item and error in
memcache/memcache_test.go and v2/memcache/memcache_test.go to satisfy
Go 1.26 printf vet checks.
- Raise TestAPICallAllocations upper bound in internal/api_test.go
from 86 to 90 to account for Go 1.26+ runtime allocations.
* ci: pin Python 3.12 for dev_appserver and scope v2 test patterns
- Replace system python3 install with actions/setup-python (3.12) in
ci.yml and ci-v2.yaml because ubuntu-latest ships Python 3.13+, which
removed the stdlib cgi module required by dev_appserver.py (webapp2).
- Warm dev_appserver.py Python bytecode cache before go test so the first
aetest startup doesn't exceed its 15s default timeout.
- Scope go test patterns in ci-v2.yaml to ./... and ./internal/... so Go
tests the local v2 module without scanning google.golang.org/appengine@v1.6.8
from indirect dependency s2a-go.
This repository supports the Go runtime on App Engine standard. It provides APIs for interacting with App Engine services. Its canonical import path is google.golang.org/appengine.
See https://cloud.google.com/appengine/docs/go/ for more information.
File issue reports and feature requests on the GitHub's issue tracker.
This package does not work on App Engine flexible.
There are many differences between the App Engine standard environment and the flexible environment.
See the documentation on upgrading to the flexible environment.
The top level directory of this repository is the appengine package. It contains the basic APIs (e.g. appengine.NewContext) that apply across APIs. Specific API packages are in subdirectories (e.g. datastore).
There is an internal subdirectory that contains service protocol buffers, plus packages required for connectivity to make API calls. App Engine apps should not directly import any package under internal.
import "appengine") packagesIf you're currently using the bare appengine packages (that is, not these ones, imported via google.golang.org/appengine), then you can use the aefix tool to help automate an upgrade to these packages.
Run go get google.golang.org/appengine/cmd/aefix to install it.
The import paths for App Engine packages are now fully qualified, based at google.golang.org/appengine. You will need to update your code to use import paths starting with that; for instance, code importing appengine/datastore will now need to import google.golang.org/appengine/datastore.
Most App Engine services are available with exactly the same API. A few APIs were cleaned up, and there are some differences:
appengine.Context has been replaced with the Context type from context.appengine.Context are now functions in google.golang.org/appengine/log.appengine.Timeout has been removed. Use context.WithTimeout instead.appengine.Datacenter now takes a context.Context argument.datastore.PropertyLoadSaver has been simplified to use slices in place of channels.delay.Call now returns an error.search.FieldLoadSaver now handles document metadata.urlfetch.Transport no longer has a Deadline field; set a deadline on the context.Context instead.aetest no longer declares its own Context type, and uses the standard one instead.taskqueue.QueueStats no longer takes a maxTasks argument. That argument has been deprecated and unused for a long time.appengine.BackendHostname and appengine.BackendInstance were for the deprecated backends feature. Use appengine.ModuleHostnameand appengine.ModuleName instead.appengine/file and parts of appengine/blobstore are deprecated. Use Google Cloud Storage if the feature you require is not present in the new blobstore package.appengine/socket is not required on App Engine flexible environment / Managed VMs. Use the standard net package instead.Key compatibility updates have been added to help customers transition from google.golang.org/appengine/datastore to cloud.google.com/go/datastore. The EnableKeyConversion enables automatic conversion from a key encoded with cloud.google.com/go/datastore to google.golang.org/appengine/datastore key type.
Enable key conversion by calling EnableKeyConversion(ctx) in the /_ah/start handler for basic and manual scaling or any handler in automatic scaling.
This start handler will enable key conversion for all handlers in the service.
http.HandleFunc("/_ah/start", func(w http.ResponseWriter, r *http.Request) {
datastore.EnableKeyConversion(appengine.NewContext(r))
})
/_ah/start is not supported for automatic scaling and /_ah/warmup is not guaranteed to run, so you must call datastore.EnableKeyConversion(appengine.NewContext(r)) before you use code that needs key conversion.
You may want to add this to each of your handlers, or introduce middleware where it's called. EnableKeyConversion is safe for concurrent use. Any call to it after the first is ignored.