1 | package edu.ucsb.cs156.courses.services.jobs; | |
2 | ||
3 | import edu.ucsb.cs156.courses.entities.Job; | |
4 | import edu.ucsb.cs156.courses.repositories.JobsRepository; | |
5 | import edu.ucsb.cs156.courses.services.CurrentUserService; | |
6 | import org.springframework.beans.factory.annotation.Autowired; | |
7 | import org.springframework.context.annotation.Lazy; | |
8 | import org.springframework.scheduling.annotation.Async; | |
9 | import org.springframework.stereotype.Service; | |
10 | ||
11 | @Service | |
12 | public class JobService { | |
13 | @Autowired private JobsRepository jobsRepository; | |
14 | ||
15 | @Autowired private CurrentUserService currentUserService; | |
16 | ||
17 | @Lazy @Autowired private JobService self; | |
18 | ||
19 | public Job runAsJob(JobContextConsumer jobFunction) { | |
20 | Job job = Job.builder().createdBy(currentUserService.getUser()).status("running").build(); | |
21 | ||
22 | jobsRepository.save(job); | |
23 |
1
1. runAsJob : removed call to edu/ucsb/cs156/courses/services/jobs/JobService::runJobAsync → KILLED |
self.runJobAsync(job, jobFunction); |
24 | ||
25 |
1
1. runAsJob : replaced return value with null for edu/ucsb/cs156/courses/services/jobs/JobService::runAsJob → KILLED |
return job; |
26 | } | |
27 | ||
28 | @Async | |
29 | public void runJobAsync(Job job, JobContextConsumer jobFunction) { | |
30 | JobContext context = new JobContext(jobsRepository, job); | |
31 | ||
32 | try { | |
33 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/services/jobs/JobContextConsumer::accept → KILLED |
jobFunction.accept(context); |
34 | } catch (Exception e) { | |
35 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT |
job.setStatus("error"); |
36 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → TIMED_OUT |
context.log(e.getMessage()); |
37 | return; | |
38 | } | |
39 | ||
40 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT |
job.setStatus("complete"); |
41 | jobsRepository.save(job); | |
42 | } | |
43 | } | |
Mutations | ||
23 |
1.1 |
|
25 |
1.1 |
|
33 |
1.1 |
|
35 |
1.1 |
|
36 |
1.1 |
|
40 |
1.1 |