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 | |
14 | private JobsRepository jobsRepository; | |
15 | ||
16 | @Autowired | |
17 | private CurrentUserService currentUserService; | |
18 | ||
19 | @Lazy | |
20 | @Autowired | |
21 | private JobService self; | |
22 | public Job runAsJob(JobContextConsumer jobFunction) { | |
23 | Job job = Job.builder() | |
24 | .createdBy(currentUserService.getUser()) | |
25 | .status("running") | |
26 | .build(); | |
27 | ||
28 | jobsRepository.save(job); | |
29 |
1
1. runAsJob : removed call to edu/ucsb/cs156/courses/services/jobs/JobService::runJobAsync → KILLED |
self.runJobAsync(job, jobFunction); |
30 | ||
31 |
1
1. runAsJob : replaced return value with null for edu/ucsb/cs156/courses/services/jobs/JobService::runAsJob → KILLED |
return job; |
32 | } | |
33 | ||
34 | | |
35 | ||
36 | @Async | |
37 | public void runJobAsync(Job job, JobContextConsumer jobFunction) { | |
38 | JobContext context = new JobContext(jobsRepository, job); | |
39 | ||
40 | try { | |
41 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/services/jobs/JobContextConsumer::accept → KILLED |
jobFunction.accept(context); |
42 | } catch (Exception e) { | |
43 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT |
job.setStatus("error"); |
44 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/services/jobs/JobContext::log → TIMED_OUT |
context.log(e.getMessage()); |
45 | return; | |
46 | } | |
47 | ||
48 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/courses/entities/Job::setStatus → TIMED_OUT |
job.setStatus("complete"); |
49 | jobsRepository.save(job); | |
50 | } | |
51 | } | |
Mutations | ||
29 |
1.1 |
|
31 |
1.1 |
|
41 |
1.1 |
|
43 |
1.1 |
|
44 |
1.1 |
|
48 |
1.1 |