如何在不同的模块上执行App Engine Go SDK的延迟包?

huangapple go评论89阅读模式
英文:

How do I execute App Engine Go SDK delay package on a different module?

问题

我有一个包含多个模块的应用程序。一个名为dispatch.yaml的文件将所有来自default模块的*/api/*调用路由到我的server模块。

以下是请求链的过程:

  1. http://myapp.appspot.com/api/webrequest - 注意我们在default模块上。
  2. http://server-dot-myapp.appspot.com/api/webrequest - 使用dispatch.yaml进行重定向到server模块,其中使用delay package执行appengine.delay.Call
  3. 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:

  1. http://myapp.appspot.com/api/webrequest - Note we are on the default module.
  2. http://server-dot-myapp.appspot.com/api/webrequest - Redirection with dispatch.yaml to the server module where appengine.delay.Call is made using the delay package.
  3. http://myapp.appspot.com/_ah/queue/go/delay - The appengine.delay.Func is 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)

huangapple
  • 本文由 发表于 2013年11月5日 06:01:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/19778059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定