private void tryUpdate(JobExecution jobExecution) { Entity jobExecutionCopy = new DynamicEntity(jobExecution.getEntityType()); jobExecutionCopy.set(jobExecution); try { dataService.update(jobExecutionCopy.getEntityType().getId(), jobExecutionCopy); } catch (Exception ex) { LOG.warn("Error updating job execution", ex); } } }
@SuppressWarnings("unchecked") private Job saveExecutionAndCreateJob(JobExecution jobExecution) { String entityTypeId = jobExecution.getEntityType().getId(); dataService.add(entityTypeId, jobExecution); try { JobFactory jobFactory = jobFactoryRegistry.getJobFactory(jobExecution); return jobFactory.createJob(jobExecution); } catch (RuntimeException ex) { LOG.error("Error creating job for JobExecution.", ex); jobExecution.setStatus(JobExecution.Status.FAILED); dataService.update(entityTypeId, jobExecution); throw ex; } }
/** * 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); if (scheduledJob == null) { throw new UnknownEntityException(SCHEDULED_JOB, scheduledJobId); } 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; } }