com.github.hengboy.job.schedule.runnable.MicroJobExecuteRetryQueueRunnable Maven / Gradle / Ivy
/*
* Copyright [2019] [恒宇少年 - 于起宇]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.hengboy.job.schedule.runnable;
import com.github.hengboy.job.core.thread.JobThread;
import com.github.hengboy.job.schedule.queue.bean.JobQueueBean;
import com.github.hengboy.job.schedule.resource.MicroJobScheduleResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 任务执行重试队列线程
*
* @author:恒宇少年 - 于起宇
*
* DateTime:2019-02-21 10:31
* Blog:http://blog.yuqiyu.com
* WebSite:http://www.jianshu.com/u/092df3f77bca
* Gitee:https://gitee.com/hengboy
* GitHub:https://github.com/hengyuboy
*/
public class MicroJobExecuteRetryQueueRunnable implements Runnable {
/**
* logger instance
*/
static Logger logger = LoggerFactory.getLogger(MicroJobExecuteRetryQueueRunnable.class);
/**
* 读取任务执行队列内等待执行的任务
* 每次读取一条,该线程项目启动后一直监听队列集合
*/
@Override
public void run() {
while (true) {
try {
// 从队列内取出一个任务
JobQueueBean jobQueueBean = MicroJobScheduleResource.JOB_RECOVERY_RETRY_QUEUE.take();
if (jobQueueBean != null) {
logger.info("Execute job [{}] retry logic.", jobQueueBean.getJobQueueKey());
JobThread.execute(new MicroJobExecuteRunnable(jobQueueBean));
}
} catch (Exception e) {
if (e instanceof InterruptedException) {
logger.error("task from job queue error", e);
}
}
}
}
}