使用Grails触发立即Quartz作业时触发错误

时间:2014-01-02 20:05:36

标签: exception grails quartz-scheduler

我正在建立一个系统,用户可以请求异步运行任务。

我将这些任务存储在Grails Domain Class ScheduledTask 的表格中。

我有两个Quartz Jobs

  • CheckForScheduledTasksJob
    • 每30秒触发一次
  • RunActionJob
    • 需要时根据需要触发
    • (将来会有一系列可配置的数量。)

目前代码流程为:

CheckForScheduledTasksJob

CheckForScheduledTasksJob {
    void execute() {
        taskService.checkForScheduledTasks()
    }
}

TaskService

void checkForScheduledTasks() {
    ScheduledTask scheduleTask = getNextPendingTask()

    if (scheduleTask) {
         Map params = [ scheduleTask:scheduleTask ]
         RunActionJob.triggerNow(params)
    }
}

此时我收到以下错误:

| Error 2014-01-02 15:00:01,112 [quartzScheduler_QuartzSchedulerThread] ERROR core.ErrorLogger  - An error occurred while scanning for the next triggers to fire.
Message: Couldn't acquire next trigger: Couldn't retrieve trigger: com.mypath.RunActionJob
    Line | Method
->> 2848 | acquireNextTrigger        in org.quartz.impl.jdbcjobstore.JobStoreSupport
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   2759 | execute                   in org.quartz.impl.jdbcjobstore.JobStoreSupport$40
|   2757 | execute . . . . . . . . . in     ''
|   3787 | executeInNonManagedTXLock in org.quartz.impl.jdbcjobstore.JobStoreSupport
|   2756 | acquireNextTriggers . . . in     ''
^    272 | run                       in org.quartz.core.QuartzSchedulerThread
Caused by JobPersistenceException: Couldn't retrieve trigger: com.mypath.RunActionJob
->> 1533 | retrieveTrigger           in org.quartz.impl.jdbcjobstore.JobStoreSupport
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   2808 | acquireNextTrigger        in     ''
|   2759 | execute . . . . . . . . . in org.quartz.impl.jdbcjobstore.JobStoreSupport$40
|   2757 | execute                   in     ''
|   3787 | executeInNonManagedTXLock in org.quartz.impl.jdbcjobstore.JobStoreSupport
|   2756 | acquireNextTriggers       in     ''
^    272 | run . . . . . . . . . . . in org.quartz.core.QuartzSchedulerThread

RunActionJob 的代码仍在开发中。到目前为止看起来像是:

class RunActionJob implements InterruptableJob, Serializable {
    boolean interrupted = false

    static triggers = {
    }

    void execute(JobExecutionContext context) {
        log.info ("HERE " + (new Date()))

        ScheduledTask task = context.getMergedJobDataMap()?.scheduleTask 

        return
    }

    void interrupt() {
        interrupted = true
    }

}

提前感谢您的任何帮助或回复。

1 个答案:

答案 0 :(得分:0)

通过反复试验,我最终发现这个问题的原因是在params中传递了ScheduledTask类。我认为该类存在序列化错误。

如果我只是在params中传递ScheduledTask.id,然后将id转换为RunActionJob中的完整对象,那么一切都按预期开始工作。