All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hengboy.job.schedule.quartz.bean.MicroJobExecuteBean Maven / Gradle / Ivy

There is a newer version: 0.0.3.RELEASE
Show newest version
package com.github.hengboy.job.schedule.quartz.bean;

import com.github.hengboy.job.schedule.queue.bean.JobQueueBean;
import com.github.hengboy.job.schedule.resource.MicroJobScheduleResource;
import com.github.hengboy.job.schedule.store.JobStore;
import com.github.hengboy.job.schedule.store.model.JobExecuteQueue;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * 任务调度执行实体
 *
 * @author:于起宇 

* ================================ * Created with IDEA. * Date:2019-01-25 * Time:15:07 * 个人博客:http://blog.yuqiyu.com * 简书:http://www.jianshu.com/u/092df3f77bca * 码云:https://gitee.com/hengboy * GitHub:https://github.com/hengyuboy * ================================ *

*/ public class MicroJobExecuteBean extends QuartzJobBean { /** * logger instance */ static Logger logger = LoggerFactory.getLogger(MicroJobExecuteBean.class); /** * 任务数据源 */ @Autowired private JobStore jobStore; /** * 任务执行的统一入口方法 * 由该方法将任务执行写入线程任务处理队列 * - 写入任务BlockingQueue * - 写入执行日志 * * @param context quartz执行上下文 * @throws JobExecutionException 任务执行异常 */ @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { /* * 查询当前quartz任务的jobKey信息 * job->name:micro job queue id * job->group:micro job key */ JobKey jobKey = context.getJobDetail().getKey(); try { // 查询任务执行队列信息 JobExecuteQueue jobExecuteQueue = jobStore.selectJobQueueById(jobKey.getName()); // 添加任务日志信息 String jobLogId = jobStore.addJobLog(jobKey.getName()); // 构造任务执行实体 JobQueueBean jobQueueBean = JobQueueBean.builder() .jobExecuteAway(jobExecuteQueue.getJeqExecuteAway()) .jobExecuteParam(jobExecuteQueue.getJeqExecuteParam()) .jobId(jobExecuteQueue.getJeqJobId()) .jobKey(jobKey.getGroup()) .jobQueueId(jobExecuteQueue.getJeqId()) .jobQueueKey(jobExecuteQueue.getJeqQueueKey()) .lbStrategy(jobExecuteQueue.getJeqLbStrategy()) .retryCount(jobExecuteQueue.getJeqRetryCount()) .executeLogId(jobLogId) .build(); // 放置任务内存执行队列,执行任务 MicroJobScheduleResource.JOB_EXECUTE_QUEUE.put(jobQueueBean); } catch (Exception e) { logger.error("Job [" + jobKey.getName() + "] execute error", e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy