duanqu9292 2019-05-22 04:30
浏览 94

Go112标准运行时中Appengine任务队列的正确上下文是什么

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

  • 写回答

2条回答 默认 最新

  • doukezi4606 2019-06-16 16:24
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路