gpt4 book ai didi

grails - quartz 服务

转载 作者:行者123 更新时间:2023-12-02 14:45:09 24 4
gpt4 key购买 nike

我用Grails编写了一个应用程序,但是 quartz 存在一些问题。
我想从数据库中获取用户,然后再获取其服务器。
如果有任何服务器,我想检查每台服务器上的PING命令,但会收到如下消息:

" [quartzScheduler_Worker-1] ERROR listeners.ExceptionPrinterJobListener - Exception occurred in job: GRAILS_JOBS. Message: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. Line | Method ->> 96 | execute in grails.plugins.quartz.GrailsJobFactory$GrailsJob - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 216 | run in org.quartz.core.JobRunShell ^ 549 | run . . in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. ->> 131 | currentRequestAttributes in org.springframework.web.context.request.RequestContextHolder"



这是我的代码:
 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)
}

有人知道怎么了吗?

最佳答案

这是因为您指的是session.user.loginsession期间没有Job
想象一下,当没有用户登录时作业就开始了-那么您指的是哪个用户?

因此,要么检查User.list()中的每个用户,要么使一个单例bean与用户一起排队。

关于grails - quartz 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13710436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com