/** * Executes a job in the calling thread. * * @param <T> Job result type * @param job the {@link Job} to execute * @param progress {@link Progress} to report progress to * @param jobExecutionContext {@link Authentication} to run the job with * @return the result of the job execution * @throws JobExecutionException if job execution throws an exception */ <T> T call(Job<T> job, Progress progress, JobExecutionContext jobExecutionContext) { return runWithContext(jobExecutionContext, () -> tryCall(job, progress)); }
public JobExecutor( DataService dataService, EntityManager entityManager, JobExecutionUpdater jobExecutionUpdater, MailSender mailSender, ExecutorService executorService, JobFactoryRegistry jobFactoryRegistry, JobExecutionContextFactory jobExecutionContextFactory) { this.dataService = requireNonNull(dataService); this.entityManager = requireNonNull(entityManager); this.jobExecutionUpdater = requireNonNull(jobExecutionUpdater); this.mailSender = requireNonNull(mailSender); this.executorService = requireNonNull(executorService); this.jobFactoryRegistry = jobFactoryRegistry; this.jobExecutionContextFactory = requireNonNull(jobExecutionContextFactory); this.jobExecutionTemplate = new JobExecutionTemplate(); this.gson = new Gson(); }
private void runJob(JobExecution jobExecution, Job<?> job) { JobExecutionContext jobExecutionContext = jobExecutionContextFactory.createJobExecutionContext(jobExecution); Progress progress = new ProgressImpl(jobExecution, jobExecutionUpdater, mailSender); jobExecutionTemplate.call(job, progress, jobExecutionContext); }
private <T> T tryCall(Job<T> job, Progress progress) { progress.start(); try { T result = job.call(progress); progress.success(); return result; } catch (Exception ex) { LOG.warn("Error executing job", ex); progress.failed(createFailureMessage(ex), ex); throw new JobExecutionException(ex); } }