英文:
How do I execute App Engine Go SDK delay package on a different module?
问题
我有一个包含多个模块的应用程序。一个名为dispatch.yaml的文件将所有来自default模块的*/api/*调用路由到我的server模块。
以下是请求链的过程:
- http://myapp.appspot.com/api/webrequest - 注意我们在default模块上。
- http://server-dot-myapp.appspot.com/api/webrequest - 使用
dispatch.yaml进行重定向到server模块,其中使用delay package执行appengine.delay.Call。 - http://myapp.appspot.com/_ah/queue/go/delay -
appengine.delay.Func在default模块上被调用,而不是我期望的http://server-dot-myapp.appspot.com/_ah/queue/go/delay。
我该如何使appengine.delay.Func在http://server-dot-myapp.appspot.com/_ah/queue/go/delay上执行?
请注意,如果我直接调用http://server-dot-myapp.appspot.com/api/webrequest而不使用dispatch.yaml重定向,一切都按预期工作,并且appengine.delay.Func会被调用,调用的URL是http://server-dot-myapp.appspot.com/_ah/queue/go/delay。
英文:
I have an app with several modules. A dispatch.yaml file routes all */api/* calls from my default module to my server module.
The following request chain happens:
- http://myapp.appspot.com/api/webrequest - Note we are on the default module.
- http://server-dot-myapp.appspot.com/api/webrequest - Redirection with
dispatch.yamlto the server module whereappengine.delay.Callis made using the delay package. - http://myapp.appspot.com/_ah/queue/go/delay - The
appengine.delay.Funcis called on the default module instead of http://server-dot-myapp.appspot.com/_ah/queue/go/delay like I would expect.
How can I make my appengine.delay.Func execute with http://server-dot-myapp.appspot.com/_ah/queue/go/delay?
Note that if I call http://server-dot-myapp.appspot.com/api/webrequest directly without using the dispatch.yaml redirect, everything workes as expected and appengine.delay.Func gets called with http://server-dot-myapp.appspot.com/_ah/queue/go/delay.
答案1
得分: 3
这是由于App Engine中的不一致性导致的。请参考Google Groups的讨论以获取更多信息。
基本上,您需要使用appengine.delay.Task而不是appengine.delay.Call,并将Host参数设置为您想要的模块主机名:
t := myDelayFunc.Task("myparam")
t.Header = make(map[string][]string)
hostName, err := appengine.ModuleHostname(context, "[your module name]", "", "")
t.Header.Set("Host", hostName)
taskqueue.Add(context, t)
英文:
This is due to an incongruity in App Engine. See Google Groups discussion for further information.
Essentially instead of using appengine.delay.Call you use appengine.delay.Task and set the Host param to the module host name you want:
t := myDelayFunc.Task("myparam")
t.Header = make(map[string][]string)
hostName, err := appengine.ModuleHostname(context, "[your module name]", "", "")
t.Header.Set("Host", hostName)
taskqueue.Add(context, t)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论