Grails 执行器 - 无法异步使用 OauthService
我安装了 grails 执行器插件,这样我就可以运行一些需要一段时间才能执行的后台任务。该任务要求我使用 OauthService 调用 LinkedIn API。问题是我似乎无法在异步块中调用 OauthService.accessResource,而完全相同的代码则可以正常执行。这是代码,经过简化以说明问题:
import org.grails.plugins.oauth.OauthService
class DemoController {
OauthService oauthService
def demo() {
runAsync {
println "ASYNC BEGIN"
def baseURL = "http://api.linkedin.com/v1/people-search?keywords=blah"
def async_response = oauthService.accessResource( baseURL, 'linkedin', [key:session.oauthToken.key, secret:session.oauthToken.secret], 'GET')
println "ASYNC END"
}
println "SYNC BEGIN"
def baseURL = "http://api.linkedin.com/v1/people-search?keywords=blah"
def sync_response = oauthService.accessResource( baseURL, 'linkedin', [key:session.oauthToken.key, secret:session.oauthToken.secret], 'GET')
println "SYNC END"
}
}
这是输出:
SYNC BEGIN
2012-01-12 14:55:07,163 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Attempting to access protected resource
2012-01-12 14:55:07,163 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Executing GET to http://api.linkedin.com/v1/people-search?keywords=blah
ASYNC BEGIN
2012-01-12 14:55:07,780 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Reading response body
2012-01-12 14:55:07,781 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Response body read successfully
SYNC END
异步进程似乎在 oauthService.accessResource 上停止,之后没有执行任何操作。我没有得到其他输出......
有什么想法吗?
感谢您的帮助。
(顺便说一句,我使用的是 grails 2.0,groovy 1.8.5)
I installed the grails executor plugin so I can run some background task that takes a while to execute. The task requires that I call LinkedIn APIs using OauthService. The problem is that I can't seem to be able to call OauthService.accessResource in the asynchronous block, while the exact same code executes fine otherwise. Here's the code, simplified to illustrate the problem :
import org.grails.plugins.oauth.OauthService
class DemoController {
OauthService oauthService
def demo() {
runAsync {
println "ASYNC BEGIN"
def baseURL = "http://api.linkedin.com/v1/people-search?keywords=blah"
def async_response = oauthService.accessResource( baseURL, 'linkedin', [key:session.oauthToken.key, secret:session.oauthToken.secret], 'GET')
println "ASYNC END"
}
println "SYNC BEGIN"
def baseURL = "http://api.linkedin.com/v1/people-search?keywords=blah"
def sync_response = oauthService.accessResource( baseURL, 'linkedin', [key:session.oauthToken.key, secret:session.oauthToken.secret], 'GET')
println "SYNC END"
}
}
Here's the output :
SYNC BEGIN
2012-01-12 14:55:07,163 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Attempting to access protected resource
2012-01-12 14:55:07,163 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Executing GET to http://api.linkedin.com/v1/people-search?keywords=blah
ASYNC BEGIN
2012-01-12 14:55:07,780 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Reading response body
2012-01-12 14:55:07,781 ["http-bio-8080"-exec-10] DEBUG oauth.OauthService - Response body read successfully
SYNC END
The asynchronous process just seems to stall on oauthService.accessResource and nothing gets executed after that. I get no other output ...
Any ideas ?
Thanks for your help.
(BTW I'm using grails 2.0, groovy 1.8.5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论