use of org.molgenis.jobs.model.ScheduledJob in project molgenis by molgenis.
the class JobSchedulerTest method scheduleInvalidCronExpression.
@Test(expectedExceptions = MolgenisValidationException.class)
public 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);
jobScheduler.schedule(scheduledJob);
}
use of org.molgenis.jobs.model.ScheduledJob in project molgenis by molgenis.
the class JobScheduler method runNow.
/**
* Executes a {@link ScheduledJob} immediately.
*
* @param scheduledJobId ID of the {@link ScheduledJob} to run
*/
public synchronized void runNow(String scheduledJobId) {
ScheduledJob scheduledJob = getJob(scheduledJobId);
try {
JobKey jobKey = new JobKey(scheduledJobId, SCHEDULED_JOB_GROUP);
if (quartzScheduler.checkExists(jobKey)) {
// Run job now
quartzScheduler.triggerJob(jobKey);
} else {
// Schedule with 'now' trigger
Trigger trigger = newTrigger().withIdentity(scheduledJobId, SCHEDULED_JOB_GROUP).startNow().build();
schedule(scheduledJob, trigger);
}
} catch (SchedulerException e) {
LOG.error("Error runNow ScheduledJob", e);
throw new MolgenisDataException("Error job runNow", e);
}
}
use of org.molgenis.jobs.model.ScheduledJob in project molgenis by molgenis.
the class JobExecutor method executeScheduledJob.
/**
* Executes a {@link ScheduledJob} in the current thread.
*
* @param scheduledJobId ID of the {@link ScheduledJob} to run
*/
@RunAsSystem
public void executeScheduledJob(String scheduledJobId) {
ScheduledJob scheduledJob = dataService.findOneById(SCHEDULED_JOB, scheduledJobId, ScheduledJob.class);
JobExecution jobExecution = createJobExecution(scheduledJob);
Job molgenisJob = saveExecutionAndCreateJob(jobExecution);
try {
runJob(jobExecution, molgenisJob);
} catch (Exception ex) {
LOG.error("Error creating job for JobExecution.", ex);
jobExecution.setStatus(JobExecution.Status.FAILED);
jobExecution.setProgressMessage(ex.getMessage());
dataService.update(jobExecution.getEntityType().getId(), jobExecution);
throw ex;
}
}
use of org.molgenis.jobs.model.ScheduledJob in project molgenis by molgenis.
the class JobSchedulerTest method scheduleExisting.
@Test
public void scheduleExisting() throws SchedulerException {
ScheduledJob scheduledJob = scheduledJobFactory.create();
scheduledJob.setId(id);
scheduledJob.set(ScheduledJobMetadata.CRON_EXPRESSION, " 0/20 * * * * ?");
scheduledJob.set(ScheduledJobMetadata.NAME, "name");
scheduledJob.set(ScheduledJobMetadata.ACTIVE, true);
scheduledJob.setType(scheduledJobType);
when(quartzScheduler.checkExists(jobKey)).thenReturn(true);
when(dataService.findOneById(SCHEDULED_JOB, id, ScheduledJob.class)).thenReturn(scheduledJob);
jobScheduler.schedule(scheduledJob);
verify(quartzScheduler).deleteJob((jobKey));
verify(quartzScheduler).scheduleJob(ArgumentMatchers.any(JobDetail.class), ArgumentMatchers.any(Trigger.class));
}
use of org.molgenis.jobs.model.ScheduledJob in project molgenis by molgenis.
the class JobSchedulerTest method schedule.
@Test
public void schedule() throws SchedulerException {
ScheduledJob scheduledJob = scheduledJobFactory.create();
scheduledJob.setId(id);
scheduledJob.set(ScheduledJobMetadata.CRON_EXPRESSION, " 0/20 * * * * ?");
scheduledJob.set(ScheduledJobMetadata.NAME, "name");
scheduledJob.set(ScheduledJobMetadata.ACTIVE, true);
scheduledJob.setType(scheduledJobType);
when(quartzScheduler.checkExists(jobKey)).thenReturn(false);
jobScheduler.schedule(scheduledJob);
verify(quartzScheduler).scheduleJob(ArgumentMatchers.any(JobDetail.class), ArgumentMatchers.any(Trigger.class));
}
Aggregations