1 | package edu.ucsb.cs156.frontiers.services.jobs; | |
2 | ||
3 | import org.springframework.beans.factory.annotation.Autowired; | |
4 | import org.springframework.context.annotation.Lazy; | |
5 | import org.springframework.scheduling.annotation.Async; | |
6 | import org.springframework.stereotype.Service; | |
7 | ||
8 | import edu.ucsb.cs156.frontiers.entities.Job; | |
9 | import edu.ucsb.cs156.frontiers.repositories.JobsRepository; | |
10 | import edu.ucsb.cs156.frontiers.services.CurrentUserService; | |
11 | ||
12 | @Service | |
13 | public class JobService { | |
14 | @Autowired private JobsRepository jobsRepository; | |
15 | ||
16 | @Autowired private CurrentUserService currentUserService; | |
17 | ||
18 | @Lazy @Autowired private JobService self; | |
19 | ||
20 | public Job runAsJob(JobContextConsumer jobFunction) { | |
21 | Job job = Job.builder().createdBy(currentUserService.getUser()).status("running").build(); | |
22 | ||
23 | jobsRepository.save(job); | |
24 |
1
1. runAsJob : removed call to edu/ucsb/cs156/frontiers/services/jobs/JobService::runJobAsync → KILLED |
self.runJobAsync(job, jobFunction); |
25 | ||
26 |
1
1. runAsJob : replaced return value with null for edu/ucsb/cs156/frontiers/services/jobs/JobService::runAsJob → KILLED |
return job; |
27 | } | |
28 | ||
29 | @Async | |
30 | public void runJobAsync(Job job, JobContextConsumer jobFunction) { | |
31 | JobContext context = new JobContext(jobsRepository, job); | |
32 | ||
33 | try { | |
34 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/frontiers/services/jobs/JobContextConsumer::accept → KILLED |
jobFunction.accept(context); |
35 | } catch (Exception e) { | |
36 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/frontiers/entities/Job::setStatus → TIMED_OUT |
job.setStatus("error"); |
37 | context.log(e.getMessage()); | |
38 | return; | |
39 | } | |
40 | ||
41 |
1
1. runJobAsync : removed call to edu/ucsb/cs156/frontiers/entities/Job::setStatus → TIMED_OUT |
job.setStatus("complete"); |
42 | jobsRepository.save(job); | |
43 | } | |
44 | ||
45 | public String getJobLogs(Long jobId) { | |
46 | Job job = | |
47 | jobsRepository | |
48 | .findById(jobId) | |
49 |
1
1. lambda$getJobLogs$0 : replaced return value with null for edu/ucsb/cs156/frontiers/services/jobs/JobService::lambda$getJobLogs$0 → KILLED |
.orElseThrow(() -> new IllegalArgumentException("Job not found")); |
50 | ||
51 | String log = job.getLog(); | |
52 |
1
1. getJobLogs : negated conditional → KILLED |
return log != null ? log : ""; |
53 | } | |
54 | } | |
Mutations | ||
24 |
1.1 |
|
26 |
1.1 |
|
34 |
1.1 |
|
36 |
1.1 |
|
41 |
1.1 |
|
49 |
1.1 |
|
52 |
1.1 |