com.ruoyi.common.exception.job.TaskException Java Examples

The following examples show how to use com.ruoyi.common.exception.job.TaskException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: supplierShop   Author: guchengwuyue   File: ScheduleUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 设置定时任务策略
 */
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
        throws TaskException
{
    switch (job.getMisfirePolicy())
    {
        case ScheduleConstants.MISFIRE_DEFAULT:
            return cb;
        case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
            return cb.withMisfireHandlingInstructionIgnoreMisfires();
        case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
            return cb.withMisfireHandlingInstructionFireAndProceed();
        case ScheduleConstants.MISFIRE_DO_NOTHING:
            return cb.withMisfireHandlingInstructionDoNothing();
        default:
            throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
                    + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
    }
}
 
Example #2
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: ScheduleUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 设置定时任务策略
 */
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
        throws TaskException
{
    switch (job.getMisfirePolicy())
    {
        case ScheduleConstants.MISFIRE_DEFAULT:
            return cb;
        case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
            return cb.withMisfireHandlingInstructionIgnoreMisfires();
        case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
            return cb.withMisfireHandlingInstructionFireAndProceed();
        case ScheduleConstants.MISFIRE_DO_NOTHING:
            return cb.withMisfireHandlingInstructionDoNothing();
        default:
            throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
                    + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
    }
}
 
Example #3
Source Project: ruoyiplus   Author: kongshanxuelin   File: ScheduleUtils.java    License: MIT License 6 votes vote down vote up
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
        throws TaskException
{
    switch (job.getMisfirePolicy())
    {
        case ScheduleConstants.MISFIRE_DEFAULT:
            return cb;
        case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
            return cb.withMisfireHandlingInstructionIgnoreMisfires();
        case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
            return cb.withMisfireHandlingInstructionFireAndProceed();
        case ScheduleConstants.MISFIRE_DO_NOTHING:
            return cb.withMisfireHandlingInstructionDoNothing();
        default:
            throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
    }
}
 
Example #4
Source Project: supplierShop   Author: guchengwuyue   File: SysJobController.java    License: MIT License 5 votes vote down vote up
/**
 * 新增保存调度
 */
@Log(title = "定时任务", businessType = BusinessType.INSERT)
@RequiresPermissions("monitor:job:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysJob job) throws SchedulerException, TaskException
{
    return toAjax(jobService.insertJob(job));
}
 
Example #5
Source Project: supplierShop   Author: guchengwuyue   File: SysJobController.java    License: MIT License 5 votes vote down vote up
/**
 * 修改保存调度
 */
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@RequiresPermissions("monitor:job:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysJob job) throws SchedulerException, TaskException
{
    return toAjax(jobService.updateJob(job));
}
 
Example #6
Source Project: supplierShop   Author: guchengwuyue   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 项目启动时,初始化定时器 
 * 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
 */
@PostConstruct
public void init() throws SchedulerException, TaskException
{
    List<SysJob> jobList = jobMapper.selectJobAll();
    for (SysJob job : jobList)
    {
        updateSchedulerJob(job, job.getJobGroup());
    }
}
 
Example #7
Source Project: supplierShop   Author: guchengwuyue   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 新增任务
 * 
 * @param job 调度信息 调度信息
 */
@Override
@Transactional
public int insertJob(SysJob job) throws SchedulerException, TaskException
{
    job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
    int rows = jobMapper.insertJob(job);
    if (rows > 0)
    {
        ScheduleUtils.createScheduleJob(scheduler, job);
    }
    return rows;
}
 
Example #8
Source Project: supplierShop   Author: guchengwuyue   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 更新任务的时间表达式
 * 
 * @param job 调度信息
 */
@Override
@Transactional
public int updateJob(SysJob job) throws SchedulerException, TaskException
{
    SysJob properties = selectJobById(job.getJobId());
    int rows = jobMapper.updateJob(job);
    if (rows > 0)
    {
        updateSchedulerJob(job, properties.getJobGroup());
    }
    return rows;
}
 
Example #9
Source Project: supplierShop   Author: guchengwuyue   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 更新任务
 * 
 * @param job 任务对象
 * @param jobGroup 任务组名
 */
public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
{
    Long jobId = job.getJobId();
    // 判断是否存在
    JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
    if (scheduler.checkExists(jobKey))
    {
        // 防止创建时存在数据问题 先移除,然后在执行创建操作
        scheduler.deleteJob(jobKey);
    }
    ScheduleUtils.createScheduleJob(scheduler, job);
}
 
Example #10
Source Project: supplierShop   Author: guchengwuyue   File: ScheduleUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 创建定时任务
 */
public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException
{
    Class<? extends Job> jobClass = getQuartzJobClass(job);
    // 构建job信息
    Long jobId = job.getJobId();
    String jobGroup = job.getJobGroup();
    JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();

    // 表达式调度构建器
    CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
    cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);

    // 按新的cronExpression表达式构建一个新的trigger
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup))
            .withSchedule(cronScheduleBuilder).build();

    // 放入参数,运行时的方法可以获取
    jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);

    // 判断是否存在
    if (scheduler.checkExists(getJobKey(jobId, jobGroup)))
    {
        // 防止创建时存在数据问题 先移除,然后在执行创建操作
        scheduler.deleteJob(getJobKey(jobId, jobGroup));
    }

    scheduler.scheduleJob(jobDetail, trigger);

    // 暂停任务
    if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
    {
        scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
    }
}
 
Example #11
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobController.java    License: MIT License 5 votes vote down vote up
/**
 * 新增定时任务
 */
@PreAuthorize("@ss.hasPermi('monitor:job:add')")
@Log(title = "定时任务", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
{
    return toAjax(jobService.insertJob(sysJob));
}
 
Example #12
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobController.java    License: MIT License 5 votes vote down vote up
/**
 * 修改定时任务
 */
@PreAuthorize("@ss.hasPermi('monitor:job:edit')")
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
{
    return toAjax(jobService.updateJob(sysJob));
}
 
Example #13
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobController.java    License: MIT License 5 votes vote down vote up
/**
 * 删除定时任务
 */
@PreAuthorize("@ss.hasPermi('monitor:job:remove')")
@Log(title = "定时任务", businessType = BusinessType.DELETE)
@DeleteMapping("/{jobIds}")
public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
{
    jobService.deleteJobByIds(jobIds);
    return AjaxResult.success();
}
 
Example #14
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
 */
@PostConstruct
public void init() throws SchedulerException, TaskException
{
    scheduler.clear();
    List<SysJob> jobList = jobMapper.selectJobAll();
    for (SysJob job : jobList)
    {
        ScheduleUtils.createScheduleJob(scheduler, job);
    }
}
 
Example #15
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 新增任务
 * 
 * @param job 调度信息 调度信息
 */
@Override
@Transactional
public int insertJob(SysJob job) throws SchedulerException, TaskException
{
    job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
    int rows = jobMapper.insertJob(job);
    if (rows > 0)
    {
        ScheduleUtils.createScheduleJob(scheduler, job);
    }
    return rows;
}
 
Example #16
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 更新任务的时间表达式
 * 
 * @param job 调度信息
 */
@Override
@Transactional
public int updateJob(SysJob job) throws SchedulerException, TaskException
{
    SysJob properties = selectJobById(job.getJobId());
    int rows = jobMapper.updateJob(job);
    if (rows > 0)
    {
        updateSchedulerJob(job, properties.getJobGroup());
    }
    return rows;
}
 
Example #17
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: SysJobServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 更新任务
 * 
 * @param job 任务对象
 * @param jobGroup 任务组名
 */
public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
{
    Long jobId = job.getJobId();
    // 判断是否存在
    JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
    if (scheduler.checkExists(jobKey))
    {
        // 防止创建时存在数据问题 先移除,然后在执行创建操作
        scheduler.deleteJob(jobKey);
    }
    ScheduleUtils.createScheduleJob(scheduler, job);
}
 
Example #18
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: ScheduleUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 创建定时任务
 */
public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException
{
    Class<? extends Job> jobClass = getQuartzJobClass(job);
    // 构建job信息
    Long jobId = job.getJobId();
    String jobGroup = job.getJobGroup();
    JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();

    // 表达式调度构建器
    CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
    cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);

    // 按新的cronExpression表达式构建一个新的trigger
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup))
            .withSchedule(cronScheduleBuilder).build();

    // 放入参数,运行时的方法可以获取
    jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);

    // 判断是否存在
    if (scheduler.checkExists(getJobKey(jobId, jobGroup)))
    {
        // 防止创建时存在数据问题 先移除,然后在执行创建操作
        scheduler.deleteJob(getJobKey(jobId, jobGroup));
    }

    scheduler.scheduleJob(jobDetail, trigger);

    // 暂停任务
    if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
    {
        scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
    }
}
 
Example #19
Source Project: RuoYi   Author: lerry903   File: SysJobController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 新增保存调度
 */
@Log(title = "定时任务", businessType = BusinessType.INSERT)
@RequiresPermissions("monitor:job:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(SysJob job) throws SchedulerException, TaskException{
    job.setCreateBy(ShiroUtils.getLoginName());
    return toAjax(jobService.insertJobCron(job));
}
 
Example #20
Source Project: RuoYi   Author: lerry903   File: SysJobController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 修改保存调度
 */
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
@RequiresPermissions("monitor:job:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(SysJob job) throws SchedulerException, TaskException {
    job.setUpdateBy(ShiroUtils.getLoginName());
    return toAjax(jobService.updateJobCron(job));
}
 
Example #21
Source Project: RuoYi   Author: lerry903   File: SysJobServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 项目启动时,初始化定时器
 */
@PostConstruct
public void init() throws SchedulerException, TaskException {
    List<SysJob> jobList = jobMapper.selectJobAll();
    for (SysJob sysJob : jobList){
        ScheduleUtils.updateScheduleJob(scheduler, sysJob);
    }
}
 
Example #22
Source Project: RuoYi   Author: lerry903   File: SysJobServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 新增任务
 *
 * @param job 调度信息 调度信息
 */
@Override
public int insertJobCron(SysJob job) throws SchedulerException, TaskException{
    job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
    int rows = jobMapper.insertJob(job);
    if (rows > 0) {
        createScheduleJob(scheduler, job);
    }
    return rows;
}
 
Example #23
Source Project: RuoYi   Author: lerry903   File: SysJobServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 更新任务的时间表达式
 *
 * @param job 调度信息
 */
@Override
public int updateJobCron(SysJob job) throws SchedulerException, TaskException{
    int rows = jobMapper.updateJob(job);
    if (rows > 0) {
        updateScheduleJob(scheduler, job);
    }
    return rows;
}
 
Example #24
Source Project: RuoYi   Author: lerry903   File: ScheduleUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 创建定时任务
 */
public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException {
    Class<? extends Job> jobClass = getQuartzJobClass(job);
    // 构建job信息
    JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(job.getJobId())).build();

    // 表达式调度构建器
    CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
    cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);

    // 按新的cronExpression表达式构建一个新的trigger
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(job.getJobId()))
            .withSchedule(cronScheduleBuilder).build();

    // 放入参数,运行时的方法可以获取
    jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
    // 判断是否存在
    if (scheduler.checkExists(getJobKey(job.getJobId()))){
        // 防止创建时存在数据问题 先移除,然后在执行创建操作
        scheduler.deleteJob(getJobKey(job.getJobId()));
    }
    scheduler.scheduleJob(jobDetail, trigger);

    // 暂停任务
    if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) {
        pauseJob(scheduler, job.getJobId());
    }
}
 
Example #25
Source Project: RuoYi   Author: lerry903   File: ScheduleUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
        throws TaskException {
    switch (job.getMisfirePolicy()) {
        case ScheduleConstants.MISFIRE_DEFAULT:
            return cb;
        case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
            return cb.withMisfireHandlingInstructionIgnoreMisfires();
        case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
            return cb.withMisfireHandlingInstructionFireAndProceed();
        case ScheduleConstants.MISFIRE_DO_NOTHING:
            return cb.withMisfireHandlingInstructionDoNothing();
        default:
            throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
    }
}
 
Example #26
Source Project: RuoYi   Author: lerry903   File: ScheduleUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 更新定时任务
 */
public static void updateScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException {
    createScheduleJob(scheduler, job);
}
 
Example #27
Source Project: supplierShop   Author: guchengwuyue   File: ISysJobService.java    License: MIT License 2 votes vote down vote up
/**
 * 新增任务
 * 
 * @param job 调度信息
 * @return 结果
 */
public int insertJob(SysJob job) throws SchedulerException, TaskException;
 
Example #28
Source Project: supplierShop   Author: guchengwuyue   File: ISysJobService.java    License: MIT License 2 votes vote down vote up
/**
 * 更新任务
 * 
 * @param job 调度信息
 * @return 结果
 */
public int updateJob(SysJob job) throws SchedulerException, TaskException;
 
Example #29
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: ISysJobService.java    License: MIT License 2 votes vote down vote up
/**
 * 新增任务
 * 
 * @param job 调度信息
 * @return 结果
 */
public int insertJob(SysJob job) throws SchedulerException, TaskException;
 
Example #30
Source Project: RuoYi-Vue   Author: yangzongzhuan   File: ISysJobService.java    License: MIT License 2 votes vote down vote up
/**
 * 更新任务
 * 
 * @param job 调度信息
 * @return 结果
 */
public int updateJob(SysJob job) throws SchedulerException, TaskException;