存储Quartz作业运行的结果

时间:2013-12-11 15:53:27

标签: scala quartz-scheduler

Quartz(2.2)中是否存在用于存储作业运行结果的神奇设置?

我天真地期望被触发的触发器存储在qrtz_fired_triggers表中,但是看起来它们在执行后被删除,然后根本没有历史记录。我错过了什么或者我自己应该这样做吗?

quartz.properties:

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.dataSource = quartzDataSource
org.quartz.jobStore.useProperties = true

org.quartz.dataSource.quartzDataSource.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.quartzDataSource.URL = <url>
org.quartz.dataSource.quartzDataSource.user = <user>
org.quartz.dataSource.quartzDataSource.password = <pw>
org.quartz.dataSource.quartzDataSource.maxConnections = 10

相关代码段:

import org.quartz.JobBuilder.newJob
import org.quartz.SimpleScheduleBuilder.simpleSchedule
import org.quartz.TriggerBuilder._
import org.quartz.impl.StdSchedulerFactory
import org.quartz._
import org.quartz.JobKey._
import org.quartz.TriggerKey._


JobHelper.at("00 50 14 11 12 ? 2013", "demojob201312111450", Map("prop"->"val"), classOf[DemoJob])


object JobHelper {

  private val scheduler = StdSchedulerFactory.getDefaultScheduler
  private val defaultGroup = "Group"

def at(cronPattern: String, name:String, jobData:Map[String, _], jobClass:Class[_ <: Job]) {
      val job = _makeJob(name, jobData, jobClass)
      val trigger = newTrigger()
         .withIdentity(name)
         .withSchedule(CronScheduleBuilder.cronSchedule(new CronExpression(cronPattern)))
         .build
      scheduler.scheduleJob(job, trigger)
  }
}

PersistJobDataAfterExecution
@DisallowConcurrentExecution
class DemoJob extends Job {
  def execute(ctx: JobExecutionContext) {
    val name = ctx.getJobDetail.getKey.getName
    val data:Map[String,Object] = (mapAsScalaMap(ctx.getMergedJobDataMap.getWrappedMap)).toMap
    println(s"""running DemoJob $name with data: $data""")    
  }
}

0 个答案:

没有答案