Search in sources :

Example 1 with QuartzJobLog

use of com.dimple.project.log.domain.QuartzJobLog in project DimpleBlog by martin-chips.

the class DashboardServiceImpl method getTaskLogStringList.

@Override
public List<String> getTaskLogStringList() {
    List<String> result = new LinkedList<>();
    List<QuartzJobLog> jobLogList = dashBoardMapper.getQuartzJobLogList();
    for (QuartzJobLog quartzJobLog : jobLogList) {
        result.add(StringUtils.format("{} : {} 执行 {}", DateUtils.showTime(quartzJobLog.getCreateTime()), quartzJobLog.getJobName(), quartzJobLog.getStatus().booleanValue() ? "成功" : "失败"));
    }
    return result;
}
Also used : QuartzJobLog(com.dimple.project.log.domain.QuartzJobLog) LinkedList(java.util.LinkedList)

Example 2 with QuartzJobLog

use of com.dimple.project.log.domain.QuartzJobLog in project DimpleBlog by martin-chips.

the class ExecutionJob method executeInternal.

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    QuartzJob quartzJob = (QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY);
    // 获取spring bean
    QuartzJobService quartzJobService = SpringUtils.getBean(QuartzJobService.class);
    QuartzJobLogService quartzJobLogService = SpringUtils.getBean(QuartzJobLogService.class);
    QuartzJobLog quartzJobLog = new QuartzJobLog();
    quartzJobLog.setJobName(quartzJob.getJobName());
    quartzJobLog.setBeanName(quartzJob.getBeanName());
    quartzJobLog.setMethodName(quartzJob.getMethodName());
    quartzJobLog.setMethodParams(quartzJob.getMethodParams());
    quartzJobLog.setCronExpression(quartzJob.getCronExpression());
    long startTime = System.currentTimeMillis();
    try {
        // 执行任务
        log.info("任务准备执行,任务名称:{}", quartzJob.getJobName());
        QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(), quartzJob.getMethodParams());
        Future<Object> future = threadPoolTaskExecutor.submit(task);
        Object result = future.get();
        log.info("任务返回值:{}", result);
        quartzJobLog.setResult(result.toString());
        long times = System.currentTimeMillis() - startTime;
        quartzJobLog.setCost(times);
        // 任务状态
        quartzJobLog.setStatus(true);
        log.info("任务执行完毕,任务名称:{} 总共耗时:{} 毫秒", quartzJob.getJobName(), times);
    } catch (Exception e) {
        log.error("任务执行失败,任务名称:{}" + quartzJob.getJobName(), e);
        long times = System.currentTimeMillis() - startTime;
        quartzJobLog.setCost(times);
        quartzJobLog.setStatus(false);
        quartzJobLog.setException(getStackTrace(e));
        // 设置为暂停状态
        quartzJob.setStatus(false);
        // 更新状态
        quartzJobService.updateQuartzJob(quartzJob);
    } finally {
        quartzJobLogService.insertQuartzJobLog(quartzJobLog);
    }
}
Also used : QuartzJobService(com.dimple.project.tool.service.QuartzJobService) QuartzJob(com.dimple.project.tool.domain.QuartzJob) QuartzJobLogService(com.dimple.project.log.service.QuartzJobLogService) QuartzJobLog(com.dimple.project.log.domain.QuartzJobLog) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

QuartzJobLog (com.dimple.project.log.domain.QuartzJobLog)2 QuartzJobLogService (com.dimple.project.log.service.QuartzJobLogService)1 QuartzJob (com.dimple.project.tool.domain.QuartzJob)1 QuartzJobService (com.dimple.project.tool.service.QuartzJobService)1 LinkedList (java.util.LinkedList)1 JobExecutionException (org.quartz.JobExecutionException)1