Grails服务与石英

时间:2012-12-04 19:29:20

标签: grails quartz-scheduler

我在Grails写了一个应用程序,但是我对石英有一些问题。 我想从DB获取用户,然后获取他的服务器。 如果有任何服务器我想在每个服务器上检查PING命令,但我收到这样的消息:

  

”       [quartzScheduler_Worker-1] ERROR listeners.ExceptionPrinterJobListener - 作业中发生异常:   GRAILS_JOBS。       消息:java.lang.IllegalStateException:找不到线程绑定请求:您是指实际的请求属性吗?   Web请求,或处理原始请求之外的请求   接收线程?如果您实际在Web请求中操作   并且仍然收到此消息,您的代码可能正在外面运行   DispatcherServlet / DispatcherPortlet:在这种情况下,请使用   RequestContextListener或RequestContextFilter公开当前   请求。         线|方法        - >> 96 |在grails.plugins.quartz.GrailsJobFactory $ GrailsJob中执行        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -       | 216 |在org.quartz.core.JobRunShell中运行       ^ 549 |跑 。 。在org.quartz.simpl.SimpleThreadPool $ WorkerThread
      由IllegalStateException引起:未找到线程绑定请求:您指的是   请求实际Web之外的属性   请求,或处理最初接收之外的请求   线?如果您实际上是在Web请求中操作而仍然   收到此消息,您的代码可能正在运行   DispatcherServlet / DispatcherPortlet:在这种情况下,请使用   RequestContextListener或RequestContextFilter公开当前   请求。        - >> 131 | org.springframework.web.context.request.RequestContextHolder中的currentRequestAttributes“

这是我的代码:

 def execute() {
     pingService.checkPing()
 }



 def checkPing = {
     User user = User.findByLogin(session.user.login) //get user
     def hostsToPing = importFromDB()
     if (!hostsToPing.isEmpty()) {
         hostsToPing.each {host ->
             doPing(host)
         }
     } else {
         //something else
     }
 }

 def importFromDB = {
     User user = User.findByLogin(session.user.login)
     def hostsList = Host.findAllByUser(user)
     hostsList
 }

 def doPing(Host host) {
     println "InetAdress: " + InetAddress.getByName(host.hostAdress)
     println "InetAdress is Rea: " + InetAddress.getLocalHost().isReachable(1000)
 }

这样的事情没有这个问题:

def doPing(Host host) {
    println "InetAdress: " + InetAddress.getByName("www.google.com")
    println "InetAdress is Reachable : " + InetAddress.getLocalHost().isReachable(1000)
}

有谁知道什么是错的?

1 个答案:

答案 0 :(得分:1)

这是因为你指的是session.user.login。期间session内没有Job。 想象一下,当没有用户登录时就开始了作业 - 你指的是什么用户呢?

因此要么检查User.list()中的每个用户,要么创建一个带有用户队列的单例bean。