/** * Saves execution in the current thread, then creates a Job and submits that for asynchronous * execution. * * @param jobExecution the {@link JobExecution} to save and submit. */ public CompletableFuture<Void> submit(JobExecution jobExecution) { return submit(jobExecution, executorService); }
@Bean public JobExecutor jobExecutor(ExecutorService executorService) { return new JobExecutor( dataService, entityManager, jobExecutionUpdater, mailSender, executorService, jobFactoryRegistry, jobExecutionContextFactory); } }
/** * Saves execution in the current thread, then creates a Job and submits that for asynchronous * execution to a specific ExecutorService. * * @param jobExecution the {@link JobExecution} to save and submit. * @param executorService the ExecutorService to run the submitted job on */ public CompletableFuture<Void> submit( JobExecution jobExecution, ExecutorService executorService) { overwriteJobExecutionUser(jobExecution); Job molgenisJob = saveExecutionAndCreateJob(jobExecution); return CompletableFuture.runAsync(() -> runJob(jobExecution, molgenisJob), executorService) .handle( (voidResult, throwable) -> { if (throwable != null) { LOG.error( format( "Job of type '%s' with id '%s' completed with exception", jobExecution.getType(), jobExecution.getIdentifier()), throwable); } return voidResult; }); }
/** * 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; } }
private JobExecution createJobExecution(ScheduledJob scheduledJob) { JobExecution jobExecution = (JobExecution) entityManager.create(scheduledJob.getType().getJobExecutionType(), POPULATE); writePropertyValues(jobExecution, getPropertyValues(scheduledJob.getParameters())); jobExecution.setFailureEmail(scheduledJob.getFailureEmail()); jobExecution.setSuccessEmail(scheduledJob.getSuccessEmail()); jobExecution.setUser(scheduledJob.getUser()); jobExecution.setScheduledJobId(scheduledJob.getId()); return jobExecution; }
@Override public void execute(JobExecutionContext context) { jobExecutor.executeScheduledJob( context.getMergedJobDataMap().getString(JobScheduler.SCHEDULED_JOB_ID)); } }
@Override public JobExecution downloadResources(List<ResourceIdentifier> resources) { if (resources.isEmpty()) { throw new IllegalArgumentException(MESSAGE_EMPTY_RESOURCES); } ResourceDownloadJobExecution jobExecution = downloadJobExecutionFactory.create(); jobExecution.setResources(resources); jobExecutor.submit(jobExecution); return jobExecution; }
@Transactional @Override public JobExecution deleteResources(List<ResourceIdentifier> resources) { if (resources.isEmpty()) { throw new IllegalArgumentException(MESSAGE_EMPTY_RESOURCES); } ResourceDeleteJobExecution jobExecution = resourceDeleteJobExecutionFactory.create(); jobExecution.setResources(resources); jobExecutor.submit(jobExecution); return jobExecution; }
@ResponseBody @PostMapping(value = "/upload", produces = MediaType.TEXT_HTML_VALUE) public String importFile(@RequestParam(value = "file") MultipartFile multipartFile) throws IOException { String filename = multipartFile.getOriginalFilename(); try (InputStream inputStream = multipartFile.getInputStream()) { fileStore.store(inputStream, filename); } OneClickImportJobExecution jobExecution = oneClickImportJobExecutionFactory.create(); jobExecution.setFile(filename); jobExecutor.submit(jobExecution); return concatEntityHref(jobExecution); }
@Override public JobExecution copyResources( List<ResourceIdentifier> resources, @Nullable String targetFolderId) { if (resources.isEmpty()) { throw new IllegalArgumentException(MESSAGE_EMPTY_RESOURCES); } Package aPackage = getPackage(targetFolderId); ResourceCopyJobExecution jobExecution = copyJobExecutionFactory.create(); jobExecution.setResources(resources); jobExecution.setTargetPackage(aPackage != null ? aPackage.getId() : null); jobExecutor.submit(jobExecution); return jobExecution; }
/** * Schedules a mappingJob for the current user. * * @param mappingProjectId ID for the mapping project to run * @param targetEntityTypeId ID for the integrated dataset * @param addSourceAttribute indication if a source attribute should be added to the target {@link * EntityType} * @return the HREF for the scheduled {@link MappingJobExecution} */ @PostMapping(value = "/submit", produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> submitMappingJob( @RequestParam String mappingProjectId, @RequestParam String targetEntityTypeId, @RequestParam(required = false) Boolean addSourceAttribute, @RequestParam(required = false, name = "package") String packageId, @RequestParam(required = false) String label) { MappingJobExecution mappingJobExecution = mappingJobExecutionFactory.create(); User currentUser = userAccountService.getCurrentUser(); mappingJobExecution.setMappingProjectId(mappingProjectId); mappingJobExecution.setTargetEntityTypeId(targetEntityTypeId); mappingJobExecution.setAddSourceAttribute(addSourceAttribute); mappingJobExecution.setPackageId(packageId); mappingJobExecution.setLabel(label); jobExecutor.submit(mappingJobExecution); return ok(concatEntityHref(mappingJobExecution)); }
@Override @RunAsSystem public void scheduleIndexJob(String transactionId) { LOG.trace("Index transaction with id {}...", transactionId); IndexActionGroup indexActionGroup = dataService.findOneById(INDEX_ACTION_GROUP, transactionId, IndexActionGroup.class); if (indexActionGroup != null) { Stream<Entity> indexActions = dataService.findAll( INDEX_ACTION, new QueryImpl<>().eq(INDEX_ACTION_GROUP_ATTR, indexActionGroup)); Map<String, Long> numberOfActionsPerEntity = indexActions.collect( groupingBy(indexAction -> indexAction.getString(ENTITY_TYPE_ID), counting())); indexStatus.addActionCounts(numberOfActionsPerEntity); IndexJobExecution indexJobExecution = indexJobExecutionFactory.create(); indexJobExecution.setIndexActionJobID(transactionId); jobExecutor .submit(indexJobExecution, executorService) .whenComplete((a, b) -> indexStatus.removeActionCounts(numberOfActionsPerEntity)); } else { LOG.debug("No index job found for id [{}].", transactionId); } }
jobExecutor.submit(sortaJobExecution);