Search in sources :

Example 1 with ScheduleJob

use of com.diboot.scheduler.entity.ScheduleJob in project diboot by dibo-software.

the class ScheduleJobServiceImpl method changeScheduleJobStatus.

@Override
public boolean changeScheduleJobStatus(Long jobId, String jobStatus) {
    boolean success = this.update(Wrappers.<ScheduleJob>lambdaUpdate().set(ScheduleJob::getJobStatus, jobStatus).eq(ScheduleJob::getId, jobId));
    if (!success) {
        throw new BusinessException(Status.FAIL_OPERATION, "更新状态失败!");
    }
    // 恢复
    if (Cons.ENABLE_STATUS.A.name().equals(jobStatus)) {
        // 如果已经存在job,那么直接恢复,否则添加job
        if (quartzSchedulerService.existJob(jobId)) {
            quartzSchedulerService.resumeJob(jobId);
        } else {
            ScheduleJob entity = this.getEntity(jobId);
            if (V.isEmpty(entity)) {
                throw new BusinessException(Status.FAIL_OPERATION, "当前任务无效!");
            }
            quartzSchedulerService.addJob(entity);
        }
    } else // 停止
    if (Cons.ENABLE_STATUS.I.name().equals(jobStatus)) {
        quartzSchedulerService.pauseJob(jobId);
    } else {
        log.warn("无效的action参数: {}", jobStatus);
    }
    return true;
}
Also used : ScheduleJob(com.diboot.scheduler.entity.ScheduleJob) BusinessException(com.diboot.core.exception.BusinessException)

Example 2 with ScheduleJob

use of com.diboot.scheduler.entity.ScheduleJob in project diboot by dibo-software.

the class ScheduleJobServiceImpl method updateEntity.

@Override
public boolean updateEntity(ScheduleJob entity) {
    // 更新后对系统的定时任务进行操作
    ScheduleJob oldJob = getEntity(entity.getId());
    boolean success = super.updateEntity(entity);
    if (!success) {
        throw new BusinessException(Status.FAIL_OPERATION, "更新定时任务失败!");
    }
    // job如果存在且参数发生了变化,那么先触发删除原来的job
    if (quartzSchedulerService.existJob(entity.getId()) && (V.notEquals(oldJob.getJobStatus(), entity.getJobStatus()) || V.notEquals(oldJob.getJobKey(), entity.getJobKey()) || V.notEquals(oldJob.getCron(), entity.getCron()) || V.notEquals(oldJob.getParamJson(), entity.getParamJson()) || V.notEquals(oldJob.getInitStrategy(), entity.getInitStrategy()))) {
        quartzSchedulerService.deleteJob(entity.getId());
    }
    if (V.equals(entity.getJobStatus(), Cons.ENABLE_STATUS.A.name())) {
        quartzSchedulerService.addJob(entity);
    }
    return true;
}
Also used : ScheduleJob(com.diboot.scheduler.entity.ScheduleJob) BusinessException(com.diboot.core.exception.BusinessException)

Example 3 with ScheduleJob

use of com.diboot.scheduler.entity.ScheduleJob in project diboot by dibo-software.

the class ScheduleJobServiceImpl method executeOnceJob.

@Override
public boolean executeOnceJob(Long jobId) {
    // 如果已经存在job,那么直接恢复,否则添加job
    if (!quartzSchedulerService.existJob(jobId)) {
        ScheduleJob entity = this.getEntity(jobId);
        if (V.isEmpty(entity)) {
            throw new BusinessException(Status.FAIL_OPERATION, "当前任务无效!");
        }
        quartzSchedulerService.addJobExecuteOnce(entity);
    } else {
        quartzSchedulerService.runJob(jobId);
    }
    return true;
}
Also used : ScheduleJob(com.diboot.scheduler.entity.ScheduleJob) BusinessException(com.diboot.core.exception.BusinessException)

Aggregations

BusinessException (com.diboot.core.exception.BusinessException)3 ScheduleJob (com.diboot.scheduler.entity.ScheduleJob)3