com.ruoyi.quartz.domain.SysJob Java Examples
The following examples show how to use
com.ruoyi.quartz.domain.SysJob.
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 File: ScheduleUtils.java From supplierShop with MIT License | 6 votes |
/** * 设置定时任务策略 */ 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 File: ScheduleUtils.java From ruoyiplus with MIT License | 6 votes |
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 File: SysJobServiceImpl.java From supplierShop with MIT License | 6 votes |
/** * 任务调度状态修改 * * @param job 调度信息 */ @Override @Transactional public int changeStatus(SysJob job) throws SchedulerException { int rows = 0; String status = job.getStatus(); if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) { rows = resumeJob(job); } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) { rows = pauseJob(job); } return rows; }
Example #4
Source File: SysJobServiceImpl.java From ruoyiplus with MIT License | 6 votes |
/** * 任务调度状态修改 * * @param job 调度信息 */ @Override public int changeStatus(SysJob job) { int rows = 0; String status = job.getStatus(); if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) { rows = resumeJob(job); } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) { rows = pauseJob(job); } return rows; }
Example #5
Source File: SysJobServiceImpl.java From ruoyiplus with MIT License | 6 votes |
/** * 项目启动时,初始化定时器 */ @PostConstruct public void init() { List<SysJob> jobList = jobMapper.selectJobAll(); for (SysJob job : jobList) { CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, job.getJobId()); // 如果不存在,则创建 if (cronTrigger == null) { ScheduleUtils.createScheduleJob(scheduler, job); } else { ScheduleUtils.updateScheduleJob(scheduler, job); } } }
Example #6
Source File: AbstractQuartzJob.java From RuoYi with Apache License 2.0 | 6 votes |
/** * 执行后 * * @param context 工作执行上下文对象 */ protected void after(JobExecutionContext context, SysJob sysJob, Exception e) { Date startTime = threadLocal.get(); threadLocal.remove(); final SysJobLog sysJobLog = new SysJobLog(); sysJobLog.setJobName(sysJob.getJobName()); sysJobLog.setJobGroup(sysJob.getJobGroup()); sysJobLog.setMethodName(sysJob.getMethodName()); sysJobLog.setMethodParams(sysJob.getMethodParams()); sysJobLog.setStartTime(startTime); sysJobLog.setEndTime(new Date()); long runMs = sysJobLog.getEndTime().getTime() - sysJobLog.getStartTime().getTime(); sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); if (e != null) { sysJobLog.setStatus(Constants.FAIL); String errorMsg = StrUtil.sub(ExceptionUtil.getExceptionMessage(e), 0, 2000); sysJobLog.setExceptionInfo(errorMsg); } else { sysJobLog.setStatus(Constants.SUCCESS); } // 写入数据库当中 SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); }
Example #7
Source File: SysJobServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 新增任务 * * @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 File: ScheduleUtils.java From supplierShop with MIT License | 5 votes |
/** * 创建定时任务 */ 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 #9
Source File: SysJobController.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 任务调度立即执行一次 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/run") @ResponseBody public AjaxResult run(SysJob job) throws SchedulerException{ jobService.run(job); return success(); }
Example #10
Source File: SysJobServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 立即运行任务 * * @param job 调度信息 */ @Override @Transactional public void run(SysJob job) throws SchedulerException { Long jobId = job.getJobId(); String jobGroup = job.getJobGroup(); SysJob properties = selectJobById(job.getJobId()); // 参数 JobDataMap dataMap = new JobDataMap(); dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap); }
Example #11
Source File: ScheduleUtils.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 立即执行任务 */ public static void run(Scheduler scheduler, SysJob job) throws SchedulerException { // 参数 JobDataMap dataMap = new JobDataMap(); dataMap.put(ScheduleConstants.TASK_PROPERTIES, job); scheduler.triggerJob(getJobKey(job.getJobId()), dataMap); }
Example #12
Source File: AbstractQuartzJob.java From supplierShop with MIT License | 5 votes |
/** * 执行后 * * @param context 工作执行上下文对象 * @param sysScheduleJob 系统计划任务 */ protected void after(JobExecutionContext context, SysJob sysJob, Exception e) { Date startTime = threadLocal.get(); threadLocal.remove(); final SysJobLog sysJobLog = new SysJobLog(); sysJobLog.setJobName(sysJob.getJobName()); sysJobLog.setJobGroup(sysJob.getJobGroup()); sysJobLog.setInvokeTarget(sysJob.getInvokeTarget()); sysJobLog.setStartTime(startTime); sysJobLog.setEndTime(new Date()); long runMs = sysJobLog.getEndTime().getTime() - sysJobLog.getStartTime().getTime(); sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); if (e != null) { sysJobLog.setStatus(Constants.FAIL); String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); sysJobLog.setExceptionInfo(errorMsg); } else { sysJobLog.setStatus(Constants.SUCCESS); } // 写入数据库当中 SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); }
Example #13
Source File: SysJobServiceImpl.java From supplierShop with MIT License | 5 votes |
/** * 恢复任务 * * @param job 调度信息 */ @Override @Transactional public int resumeJob(SysJob job) throws SchedulerException { Long jobId = job.getJobId(); String jobGroup = job.getJobGroup(); job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); int rows = jobMapper.updateJob(job); if (rows > 0) { scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); } return rows; }
Example #14
Source File: SysJobController.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 任务调度状态修改 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/changeStatus") @ResponseBody public AjaxResult changeStatus(SysJob job) throws SchedulerException{ SysJob newJob = jobService.selectJobById(job.getJobId()); newJob.setStatus(job.getStatus()); newJob.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(jobService.changeStatus(job)); }
Example #15
Source File: SysJobServiceImpl.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 新增任务 * * @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 #16
Source File: SysJobController.java From supplierShop with MIT License | 5 votes |
@Log(title = "定时任务", businessType = BusinessType.EXPORT) @RequiresPermissions("monitor:job:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysJob job) { List<SysJob> list = jobService.selectJobList(job); ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); return util.exportExcel(list, "定时任务"); }
Example #17
Source File: SysJobController.java From supplierShop with MIT License | 5 votes |
/** * 任务调度立即执行一次 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/run") @ResponseBody public AjaxResult run(SysJob job) throws SchedulerException { jobService.run(job); return success(); }
Example #18
Source File: SysJobServiceImpl.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 恢复任务 * * @param job 调度信息 */ @Override public int resumeJob(SysJob job) throws SchedulerException{ job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); int rows = jobMapper.updateJob(job); if (rows > 0) { ScheduleUtils.resumeJob(scheduler, job.getJobId()); } return rows; }
Example #19
Source File: SysJobController.java From supplierShop with MIT License | 5 votes |
/** * 任务调度状态修改 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/changeStatus") @ResponseBody public AjaxResult changeStatus(SysJob job) throws SchedulerException { SysJob newJob = jobService.selectJobById(job.getJobId()); newJob.setStatus(job.getStatus()); return toAjax(jobService.changeStatus(newJob)); }
Example #20
Source File: ScheduleUtils.java From RuoYi with Apache License 2.0 | 5 votes |
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 #21
Source File: SysJobServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 更新任务的时间表达式 * * @param job 调度信息 */ @Override public int updateJobCron(SysJob job) { int rows = jobMapper.updateJob(job); if (rows > 0) { ScheduleUtils.updateScheduleJob(scheduler, job); } return rows; }
Example #22
Source File: SysJobServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 新增任务 * * @param job 调度信息 调度信息 */ @Override public int insertJobCron(SysJob job) { job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); int rows = jobMapper.insertJob(job); if (rows > 0) { ScheduleUtils.createScheduleJob(scheduler, job); } return rows; }
Example #23
Source File: SysJobController.java From ruoyiplus with MIT License | 5 votes |
/** * 任务调度状态修改 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/changeStatus") @ResponseBody public AjaxResult changeStatus(SysJob job) { job.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(jobService.changeStatus(job)); }
Example #24
Source File: SysJobController.java From ruoyiplus with MIT License | 5 votes |
/** * 任务调度立即执行一次 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/run") @ResponseBody public AjaxResult run(SysJob job) { return toAjax(jobService.run(job)); }
Example #25
Source File: SysJobController.java From ruoyiplus with MIT License | 5 votes |
/** * 新增保存调度 */ @Log(title = "定时任务", businessType = BusinessType.INSERT) @RequiresPermissions("monitor:job:add") @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysJob job) { job.setCreateBy(ShiroUtils.getLoginName()); return toAjax(jobService.insertJobCron(job)); }
Example #26
Source File: SysJobController.java From ruoyiplus with MIT License | 5 votes |
/** * 校验cron表达式是否有效 */ @PostMapping("/checkCronExpressionIsValid") @ResponseBody public boolean checkCronExpressionIsValid(SysJob job) { return jobService.checkCronExpressionIsValid(job.getCronExpression()); }
Example #27
Source File: JobInvokeUtil.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 执行方法 * * @param sysJob 系统任务 */ public static void invokeMethod(SysJob sysJob) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Object bean = SpringUtils.getBean(sysJob.getJobName()); String methodName = sysJob.getMethodName(); String methodParams = sysJob.getMethodParams(); invokeSpringBean(bean, methodName, methodParams); }
Example #28
Source File: SysJobServiceImpl.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 更新任务的时间表达式 * * @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 #29
Source File: SysJobServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 批量删除调度信息 * * @param ids 需要删除的数据ID * @return 结果 */ @Override public void deleteJobByIds(String ids) { Long[] jobIds = Convert.toLongArray(ids); for (Long jobId : jobIds) { SysJob job = jobMapper.selectJobById(jobId); deleteJob(job); } }
Example #30
Source File: SysJobServiceImpl.java From ruoyiplus with MIT License | 5 votes |
/** * 删除任务后,所对应的trigger也将被删除 * * @param job 调度信息 */ @Override public int deleteJob(SysJob job) { int rows = jobMapper.deleteJobById(job.getJobId()); if (rows > 0) { ScheduleUtils.deleteScheduleJob(scheduler, job.getJobId()); } return rows; }