| 1 | package edu.ucsb.cs156.example.services.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.Job; | |
| 4 | import edu.ucsb.cs156.example.repositories.JobsRepository; | |
| 5 | import edu.ucsb.cs156.example.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/example/services/jobs/JobService::runJobAsync → KILLED |     self.runJobAsync(job, jobFunction); | 
| 24 | ||
| 25 | 1
1. runAsJob : replaced return value with null for edu/ucsb/cs156/example/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/example/services/jobs/JobContextConsumer::accept → KILLED |       jobFunction.accept(context); | 
| 34 |     } catch (Exception e) { | |
| 35 | 1
1. runJobAsync : removed call to edu/ucsb/cs156/example/entities/Job::setStatus → TIMED_OUT |       job.setStatus("error"); | 
| 36 |       context.log(e.getMessage()); | |
| 37 |       return; | |
| 38 |     } | |
| 39 | ||
| 40 | 1
1. runJobAsync : removed call to edu/ucsb/cs156/example/entities/Job::setStatus → TIMED_OUT |     job.setStatus("complete"); | 
| 41 |     jobsRepository.save(job); | |
| 42 |   } | |
| 43 | ||
| 44 |   public String getJobLogs(Long jobId) { | |
| 45 |     Job job = | |
| 46 |         jobsRepository | |
| 47 |             .findById(jobId) | |
| 48 | 1
1. lambda$getJobLogs$0 : replaced return value with null for edu/ucsb/cs156/example/services/jobs/JobService::lambda$getJobLogs$0 → KILLED |             .orElseThrow(() -> new IllegalArgumentException("Job not found")); | 
| 49 | ||
| 50 |     String log = job.getLog(); | |
| 51 | 1
1. getJobLogs : negated conditional → KILLED |     return log != null ? log : ""; | 
| 52 |   } | |
| 53 | } | |
| Mutations | ||
| 23 | 1.1 | |
| 25 | 1.1 | |
| 33 | 1.1 | |
| 35 | 1.1 | |
| 40 | 1.1 | |
| 48 | 1.1 | |
| 51 | 1.1 |