@Test void scheduleInvalidCronExpression() throws SchedulerException { ScheduledJob scheduledJob = scheduledJobFactory.create(); scheduledJob.setId(id); scheduledJob.set(ScheduledJobMetadata.CRON_EXPRESSION, "XXX"); scheduledJob.set(ScheduledJobMetadata.NAME, "name"); scheduledJob.set(ScheduledJobMetadata.ACTIVE, false); scheduledJob.setType(scheduledJobType); assertThrows(MolgenisValidationException.class, () -> jobScheduler.schedule(scheduledJob)); }
public synchronized void schedule(ScheduledJob scheduledJob) { String id = scheduledJob.getId(); String cronExpression = scheduledJob.getCronExpression(); String name = scheduledJob.getName(); if (!CronExpression.isValidExpression(cronExpression)) { throw new MolgenisValidationException( singleton( new ConstraintViolation("Invalid cronexpression '" + cronExpression + "'", null))); } try { if (quartzScheduler.checkExists(new JobKey(id, SCHEDULED_JOB_GROUP))) { unschedule(id); } if (!scheduledJob.isActive()) { return; } Trigger trigger = newTrigger() .withIdentity(id, SCHEDULED_JOB_GROUP) .withSchedule(cronSchedule(cronExpression)) .build(); schedule(scheduledJob, trigger); LOG.info("Scheduled Job '{}' with trigger '{}'", name, trigger); } catch (SchedulerException e) { LOG.error("Error schedule job", e); throw new ScheduledJobException("Error schedule job", e); } }
JobScheduler { public synchronized void schedule(ScheduledJob scheduledJob) { String id = scheduledJob.getId(); String cronExpression = scheduledJob.getCronExpression(); String name = scheduledJob.getName(); if (!CronExpression.isValidExpression(cronExpression)) { throw new MolgenisValidationException( singleton( new ConstraintViolation("Invalid cronexpression '" + cronExpression + "'", null))); } try { if (quartzScheduler.checkExists(new JobKey(id, SCHEDULED_JOB_GROUP))) { unschedule(id); } if (!scheduledJob.isActive()) { return; } Trigger trigger = newTrigger() .withIdentity(id, SCHEDULED_JOB_GROUP) .withSchedule(cronSchedule(cronExpression)) .build(); schedule(scheduledJob, trigger); LOG.info("Scheduled Job '{}' with trigger '{}'", name, trigger); } catch (SchedulerException e) { LOG.error("Error schedule job", e); throw new ScheduledJobException("Error schedule job", e); } } }
JobScheduler { public synchronized void schedule(ScheduledJob scheduledJob) { String id = scheduledJob.getId(); String cronExpression = scheduledJob.getCronExpression(); String name = scheduledJob.getName(); if (!CronExpression.isValidExpression(cronExpression)) { throw new MolgenisValidationException( singleton( new ConstraintViolation("Invalid cronexpression '" + cronExpression + "'", null))); } try { if (quartzScheduler.checkExists(new JobKey(id, SCHEDULED_JOB_GROUP))) { unschedule(id); } if (!scheduledJob.isActive()) { return; } Trigger trigger = newTrigger() .withIdentity(id, SCHEDULED_JOB_GROUP) .withSchedule(cronSchedule(cronExpression)) .build(); schedule(scheduledJob, trigger); LOG.info("Scheduled Job '{}' with trigger '{}'", name, trigger); } catch (SchedulerException e) { LOG.error("Error schedule job", e); throw new ScheduledJobException("Error schedule job", e); } } JobScheduler(Scheduler quartzScheduler, DataService dataService); }
JobScheduler { public synchronized void schedule(ScheduledJob scheduledJob) { String id = scheduledJob.getId(); String cronExpression = scheduledJob.getCronExpression(); String name = scheduledJob.getName(); if (!CronExpression.isValidExpression(cronExpression)) { throw new MolgenisValidationException( singleton( new ConstraintViolation("Invalid cronexpression '" + cronExpression + "'", null))); } try { if (quartzScheduler.checkExists(new JobKey(id, SCHEDULED_JOB_GROUP))) { unschedule(id); } if (!scheduledJob.isActive()) { return; } Trigger trigger = newTrigger() .withIdentity(id, SCHEDULED_JOB_GROUP) .withSchedule(cronSchedule(cronExpression)) .build(); schedule(scheduledJob, trigger); LOG.info("Scheduled Job '{}' with trigger '{}'", name, trigger); } catch (SchedulerException e) { LOG.error("Error schedule job", e); throw new ScheduledJobException("Error schedule job", e); } } JobScheduler(Scheduler quartzScheduler, DataService dataService); synchronized void runNow(String scheduledJobId); synchronized void schedule(ScheduledJob scheduledJob); void scheduleJobs(); }
JobScheduler { public synchronized void schedule(ScheduledJob scheduledJob) { String id = scheduledJob.getId(); String cronExpression = scheduledJob.getCronExpression(); String name = scheduledJob.getName(); if (!CronExpression.isValidExpression(cronExpression)) { throw new MolgenisValidationException( singleton( new ConstraintViolation("Invalid cronexpression '" + cronExpression + "'", null))); } try { if (quartzScheduler.checkExists(new JobKey(id, SCHEDULED_JOB_GROUP))) { unschedule(id); } if (!scheduledJob.isActive()) { return; } Trigger trigger = newTrigger() .withIdentity(id, SCHEDULED_JOB_GROUP) .withSchedule(cronSchedule(cronExpression)) .build(); schedule(scheduledJob, trigger); LOG.info("Scheduled Job '{}' with trigger '{}'", name, trigger); } catch (SchedulerException e) { LOG.error("Error schedule job", e); throw new ScheduledJobException("Error schedule job", e); } } JobScheduler(Scheduler quartzScheduler, DataService dataService); synchronized void runNow(String scheduledJobId); synchronized void schedule(ScheduledJob scheduledJob); void scheduleJobs();  }