I cannot get the appengine taskqueue to accept any context I throw at it:
import (
"context"
"google.golang.org/appengine"
"google.golang.org/appengine/taskqueue"
)
/* snip */
ctx:= context.Background()
task := taskqueue.NewPOSTTask("/b/mytask", params)
_, err = taskqueue.Add(ctx, task, "")
if err != nil {
return fmt.Errorf("adding background task with path %s: %v", task.Path, err)
}
I'm calling appengine.Main() in my main.go main func as stated by the go111 migration docs (But this line is missing in go112 migration docs so I'm not sure it's required).
I've tried:
context.Background()
request.Context()
appengine.NewContext(r)
appengine.BackgroundContext()
context.TODO()
All result in error:
not an App Engine context
except for appengine.BackgroundContext()
which gets:
service bridge HTTP failed: Post http://appengine.googleapis.internal:10001/rpc_http: dial tcp 169.254.169.253:10001: i/o timeout
I experienced the same problems when migrating a GAE standard project from go19 to go112 in order to use go modules. In addition I got a lot of "502 bad gateway" messages.
Replacing http.ListenAndServe() in main() with appengine.Main() fixed the context problem. Moving to go111 instead of 112 took care of the other issue. The docs and examples are not very clear on this.
The documentation for migration to 1.12 states:
Use Cloud Tasks to enqueue tasks from Go 1.12 using the cloudtasks package. You can use any App Engine service as the target of an App Engine task.
But the cloudtasks package documentation (as at today’s date) is clearly marked as beta and unstable. So the answer here is probably. This feature is unsupported.
That said, I’m using it in production under go111 without any serious issue that I have noticed so far.