| 1 | package edu.ucsb.cs156.happiercows.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.happiercows.entities.Game; | |
| 4 | import edu.ucsb.cs156.happiercows.entities.GameStats; | |
| 5 | import edu.ucsb.cs156.happiercows.repositories.GameRepository; | |
| 6 | import edu.ucsb.cs156.happiercows.services.GameStatsService; | |
| 7 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 8 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 9 | import lombok.AllArgsConstructor; | |
| 10 | import lombok.Getter; | |
| 11 | ||
| 12 | ||
| 13 | /** This job computes the stats for all games in progress and creates one new row in the GameStats table for each game. It uses the Average Cow Health Service to compute the cowhealth for each game. | |
| 14 | */ | |
| 15 | ||
| 16 | @AllArgsConstructor | |
| 17 | public class RecordGameStatsJob implements JobContextConsumer { | |
| 18 | ||
| 19 | @Getter | |
| 20 | private GameStatsService gameStatsService; | |
| 21 | ||
| 22 | @Getter | |
| 23 | private GameRepository gameRepository; | |
| 24 | ||
| 25 | @Override | |
| 26 | public void accept(JobContext ctx) throws Exception { | |
| 27 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Starting record game stats job..."); |
| 28 | Iterable<Game> allGame = gameRepository.findAll(); | |
| 29 | ||
| 30 | for (Game game : allGame) { | |
| 31 |
1
1. accept : negated conditional → KILLED |
if (!GameGate.shouldProcess(game, gameRepository, ctx)) { |
| 32 | continue; | |
| 33 | } | |
| 34 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("Starting Game id=%d (%s)...", game.getId(), game.getName())); |
| 35 | GameStats gameStats = gameStatsService.createAndSaveGameStats(game.getId()); | |
| 36 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("GameStats %d for game id=%d (%s) finished.", gameStats.getId(), game.getId(), |
| 37 | game.getName())); | |
| 38 | } | |
| 39 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Record game stats job done!"); |
| 40 | } | |
| 41 | } | |
| 42 | ||
Mutations | ||
| 27 |
1.1 |
|
| 31 |
1.1 |
|
| 34 |
1.1 |
|
| 36 |
1.1 |
|
| 39 |
1.1 |