Search in sources :

Example 1 with UnableToInterruptJobException

use of org.quartz.UnableToInterruptJobException in project incubator-gobblin by apache.

the class JobScheduler method shutDown.

@Override
protected void shutDown() throws Exception {
    LOG.info("Stopping the job scheduler");
    closer.close();
    cancelRequested = true;
    List<JobExecutionContext> currentExecutions = this.scheduler.getScheduler().getCurrentlyExecutingJobs();
    for (JobExecutionContext jobExecutionContext : currentExecutions) {
        try {
            this.scheduler.getScheduler().interrupt(jobExecutionContext.getFireInstanceId());
        } catch (UnableToInterruptJobException e) {
            LOG.error("Failed to cancel job " + jobExecutionContext.getJobDetail().getKey(), e);
        }
    }
    ExecutorsUtils.shutdownExecutorService(this.jobExecutor, Optional.of(LOG));
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobExecutionContext(org.quartz.JobExecutionContext)

Example 2 with UnableToInterruptJobException

use of org.quartz.UnableToInterruptJobException in project BRFS by zhangnianli.

the class DefaultBaseSchedulers method deleteTask.

@Override
public boolean deleteTask(SumbitTaskInterface task) throws ParamsErrorException {
    checkTask(task);
    try {
        // 不在正常运行时,不进行删除任务操作
        if (!isNormal()) {
            return false;
        }
        TriggerKey triggerKey = TriggerKey.triggerKey(task.getTaskName(), task.getTaskGroupName());
        JobKey jobKey = new JobKey(task.getTaskName(), task.getTaskGroupName());
        Scheduler scheduler = this.ssf.getScheduler(this.instanceName);
        if (!scheduler.isShutdown()) {
            // 获取触发器的状态
            int stat = getTaskStat(task);
            if (stat == -1) {
                return false;
            }
            // 1.停止触发器
            scheduler.pauseTrigger(triggerKey);
            // 2.中断正在执行的任务
            if (isExecuting(task)) {
                scheduler.interrupt(jobKey);
            }
            // 3.移除触发器
            scheduler.unscheduleJob(triggerKey);
            // 4.删除任务
            // 删除任务
            scheduler.deleteJob(jobKey);
        }
        return true;
    } catch (UnableToInterruptJobException e) {
        LOG.error("delete task error{}", e);
    } catch (SchedulerException e) {
        LOG.error("scheduler error {}", e);
    }
    return false;
}
Also used : TriggerKey(org.quartz.TriggerKey) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 3 with UnableToInterruptJobException

use of org.quartz.UnableToInterruptJobException in project BRFS by zhangnianli.

the class DefaultBaseSchedulers method pauseAllTask.

@Override
public boolean pauseAllTask() {
    try {
        // 不在正常运行时,不进行任何操作
        if (!isNormal()) {
            return false;
        }
        Scheduler scheduler = this.ssf.getScheduler(this.instanceName);
        if (!scheduler.isShutdown()) {
            // 1.停止触发器
            scheduler.pauseAll();
            JobKey currentJob;
            // 2.中断所有执行的任务
            for (JobExecutionContext jobExecut : scheduler.getCurrentlyExecutingJobs()) {
                currentJob = jobExecut.getJobDetail().getKey();
                scheduler.interrupt(currentJob);
            }
        }
        return true;
    } catch (UnableToInterruptJobException e) {
        LOG.error("{}", e);
    } catch (SchedulerException e) {
        LOG.error("{}", e);
    }
    return false;
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobExecutionContext(org.quartz.JobExecutionContext)

Aggregations

UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)3 JobExecutionContext (org.quartz.JobExecutionContext)2 JobKey (org.quartz.JobKey)2 Scheduler (org.quartz.Scheduler)2 SchedulerException (org.quartz.SchedulerException)2 TriggerKey (org.quartz.TriggerKey)1