异步作业错误 [英] Error on async job

查看:126
本文介绍了异步作业错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个不会阻止请求的异步任务。用户发出请求,任务将开始,控制器将呈现作业正在运行...,这是为了避免请求被阻塞,等待任务完成。
任务完成后,它将执行onComplete并对该任务的结果执行一些操作(例如,调用将向用户发送邮件的服务)。

  | Error 2014-09-16 17:38:56,721 [Actor Thread 3] ERROR gpars.LoggingPoolFactory  -  Async execution error:null 

代码如下:

  package testasync 

import static grails.async .Promises。*

class TestController {

def index(){
//创建作业
def job1 =任务{
println'等待10秒钟'
Thread.sleep(10000)
返回'完成'
}
//错误
job1.onError {Throwable err - > ;
println发生错误$ {err.message}
}
//成功
job1.onComplete {result - >
printlnPromise returned $ result
}
render'Job is running ...'
}

完整的堆栈跟踪:

  |错误2014-09-17 10:35:24,522 [Actor Thread 3] ERROR gpars.LoggingPoolFactory  - 异步执行错误:null 
消息:null
行|方法
- >> 72 | doCall in org.grails.async.factory.gpars.GparsPromise $ _onError_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 62 |在groovyx.gpars.dataflow.DataCallback中运行$ 1
| 1145 | java.util.concurrent.ThreadPoolExecutor中的runWorker
| 615 |在java.util.concurrent.ThreadPoolExecutor $ Worker
^ 745 |中运行跑 。 。 。在java.lang.Thread中


解决方案

框架与grails执行器插件。我在这里上传了一个非常基本的示例: https://github.com/agusl88/grails-async -job-queuqe



该代码使用的是custom版本的grails-executor插件,我从插件回购中合并了一些PR,并打包为瓶只是为了测试propuses。该插件的回购是这样的: https://github.com/basejump/grails-executor

I'm trying to create an async task that will not block the request. The user make the request, the task will start, and the controller will render "Job is running...", this is for avoid the request being blocked waiting the task to complete. Once the task is finish, it will execute the onComplete and do something with the result of that task (for example call a service that will send a mail to an user)

| Error 2014-09-16 17:38:56,721 [Actor Thread 3] ERROR gpars.LoggingPoolFactory  - Async execution error: null

The code is the following:

package testasync

import static grails.async.Promises.*

class TestController {

  def index() {
    //Create the job
    def job1 = task {
        println 'Waiting 10 seconds'
        Thread.sleep(10000)
        return 'Im done'
    }
    //On error
    job1.onError { Throwable err ->
        println "An error occured ${err.message}"
    }
    //On success
    job1.onComplete { result ->
        println "Promise returned $result"
    }
    render 'Job is running...'
  }

Complete stacktrace:

| Error 2014-09-17 10:35:24,522 [Actor Thread 3] ERROR gpars.LoggingPoolFactory  -  Async execution error: null
Message: null
   Line | Method
 ->>   72 | doCall    in org.grails.async.factory.gpars.GparsPromise$_onError_closure2
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  |     62 | run       in groovyx.gpars.dataflow.DataCallback$1
  |   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
  |    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
  ^    745 | run . . . in java.lang.Thread

解决方案

I ended using the executor framework with the grails-executor plugin. I uploaded a very basic example here: https://github.com/agusl88/grails-async-job-queuqe

That code is using a "custom" version of the grails-executor plugin, i merged some PR's from the plugin repo and packaged as jar just for testing propuses. The repo of the plugin is this: https://github.com/basejump/grails-executor

这篇关于异步作业错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆