Grails 执行器 - 无法异步使用 OauthService

发布于 2024-12-26 18:10:16 字数 1597 浏览 0 评论 0原文

我安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文