| 1 | package edu.ucsb.cs156.courses.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.courses.documents.ConvertedSection; | |
| 4 | import edu.ucsb.cs156.courses.documents.Update; | |
| 5 | import edu.ucsb.cs156.courses.models.Quarter; | |
| 6 | import edu.ucsb.cs156.courses.services.IsStaleService; | |
| 7 | import edu.ucsb.cs156.courses.services.UCSBCurriculumService; | |
| 8 | import edu.ucsb.cs156.courses.services.UpdateCoursesService; | |
| 9 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 10 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 11 | import edu.ucsb.cs156.jobs.services.JobRateLimit; | |
| 12 | import java.util.List; | |
| 13 | import lombok.AllArgsConstructor; | |
| 14 | import lombok.Builder; | |
| 15 | import lombok.Getter; | |
| 16 | import lombok.extern.slf4j.Slf4j; | |
| 17 | ||
| 18 | @Builder | |
| 19 | @Getter | |
| 20 | @AllArgsConstructor | |
| 21 | @Slf4j | |
| 22 | public class UpdateCourseDataJob implements JobContextConsumer { | |
| 23 | ||
| 24 | private String start_quarterYYYYQ; | |
| 25 | private String end_quarterYYYYQ; | |
| 26 | private List<String> subjects; | |
| 27 | private UCSBCurriculumService ucsbCurriculumService; | |
| 28 | private IsStaleService isStaleService; | |
| 29 | private boolean ifStale; | |
| 30 | private JobRateLimit jobRateLimit; | |
| 31 | private UpdateCoursesService updateCoursesService; | |
| 32 | ||
| 33 | @Override | |
| 34 | public void accept(JobContext ctx) throws Exception { | |
| 35 | ||
| 36 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 37 | String.format( | |
| 38 | "Updating courses from %s to %s for %d subjects", | |
| 39 | start_quarterYYYYQ, end_quarterYYYYQ, subjects.size())); | |
| 40 | List<Quarter> quarters = Quarter.quarterList(start_quarterYYYYQ, end_quarterYYYYQ); | |
| 41 | for (Quarter quarter : quarters) { | |
| 42 | String quarterYYYYQ = quarter.getYYYYQ(); | |
| 43 | for (String subjectArea : subjects) { | |
| 44 | // Most (subjectArea, quarterYYYYQ) pairs are not stale on a typical re-run and hit the | |
| 45 | // `continue` below with no ctx.log() call at all -- checkCancellation() gives this loop | |
| 46 | // its own cancellation checkpoint independent of whether an iteration happens to log | |
| 47 | // anything (see UpdateCourseDataJobTests for why a bare log()-only check isn't enough). | |
| 48 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::checkCancellation → KILLED |
ctx.checkCancellation(); |
| 49 | boolean isStale = isStaleService.isStale(subjectArea, quarterYYYYQ); | |
| 50 |
1
1. accept : negated conditional → KILLED |
if (ifStale) { |
| 51 |
1
1. accept : negated conditional → KILLED |
if (!isStale) { |
| 52 | continue; | |
| 53 | } | |
| 54 | } | |
| 55 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobRateLimit::sleep → KILLED |
jobRateLimit.sleep(); |
| 56 |
1
1. accept : removed call to edu/ucsb/cs156/courses/jobs/UpdateCourseDataJob::updateCourses → KILLED |
updateCourses(ctx, quarterYYYYQ, subjectArea); |
| 57 | } | |
| 58 | } | |
| 59 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Finished updating courses"); |
| 60 | } | |
| 61 | ||
| 62 | public void updateCourses(JobContext ctx, String quarterYYYYQ, String subjectArea) | |
| 63 | throws Exception { | |
| 64 |
1
1. updateCourses : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Updating courses for [" + subjectArea + " " + quarterYYYYQ + "]"); |
| 65 | ||
| 66 | List<ConvertedSection> convertedSections = | |
| 67 | ucsbCurriculumService.getConvertedSections(subjectArea, quarterYYYYQ, "A"); | |
| 68 | ||
| 69 | Update savedUpdate = | |
| 70 | updateCoursesService.upsert(convertedSections, ctx, quarterYYYYQ, subjectArea, true); | |
| 71 | ||
| 72 |
1
1. updateCourses : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 73 | String.format( | |
| 74 | "%d new sections saved, %d sections updated, %d errors, last update: %s", | |
| 75 | savedUpdate.getSaved(), | |
| 76 | savedUpdate.getUpdated(), | |
| 77 | savedUpdate.getErrors(), | |
| 78 | savedUpdate.getLastUpdate())); | |
| 79 | ||
| 80 |
1
1. updateCourses : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Saved update: " + savedUpdate); |
| 81 | } | |
| 82 | } | |
Mutations | ||
| 36 |
1.1 |
|
| 48 |
1.1 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 55 |
1.1 |
|
| 56 |
1.1 |
|
| 59 |
1.1 |
|
| 64 |
1.1 |
|
| 72 |
1.1 |
|
| 80 |
1.1 |