From d408b46b10b371ac779a83e2d965607159f6d43d Mon Sep 17 00:00:00 2001 From: Fedor Glazov Date: Sun, 10 Apr 2022 10:31:33 +0200 Subject: [PATCH] Skip over capture sorties which cause error. --- .../background_jobs/fix_captures.py | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/mod_stats_by_aircraft/background_jobs/fix_captures.py b/src/mod_stats_by_aircraft/background_jobs/fix_captures.py index 64cc5c8..565b950 100644 --- a/src/mod_stats_by_aircraft/background_jobs/fix_captures.py +++ b/src/mod_stats_by_aircraft/background_jobs/fix_captures.py @@ -2,6 +2,7 @@ from stats.models import Sortie from ..aircraft_mod_models import AircraftBucket from ..aircraft_stats_compute import get_sortie_type +from django.db.utils import DatabaseError class FixCaptures(BackgroundJob): @@ -18,29 +19,33 @@ def query_find_sorties(self, tour_cutoff): .order_by('-tour__id')) def compute_for_sortie(self, sortie): - if sortie.is_captured and sortie.is_dead: - # TODO: Refactor this "get all buckets code" into a util function. - buckets = [(AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, - filter_type='NO_FILTER', player=None))[0], - (AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, - filter_type='NO_FILTER', player=sortie.player))[0]] - filter_type = get_sortie_type(sortie) - if filter_type != 'NO_FILTER': - buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, - filter_type=filter_type, player=None))[0]) - buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, - filter_type=filter_type, player=sortie.player))[0]) - - for bucket in buckets: - bucket.captures -= 1 - bucket.update_derived_fields() - bucket.save() + try: + if sortie.is_captured and sortie.is_dead: + # TODO: Refactor this "get all buckets code" into a util function. + buckets = [(AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, + filter_type='NO_FILTER', player=None))[0], + (AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, + filter_type='NO_FILTER', player=sortie.player))[0]] + filter_type = get_sortie_type(sortie) + if filter_type != 'NO_FILTER': + buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, + filter_type=filter_type, player=None))[0]) + buckets.append((AircraftBucket.objects.get_or_create(tour=sortie.tour, aircraft=sortie.aircraft, + filter_type=filter_type, + player=sortie.player))[0]) + + for bucket in buckets: + bucket.captures -= 1 + bucket.update_derived_fields() + bucket.save() + except DatabaseError: + pass # Just ignore the sortie if it fails for some reason. Old data - not too important. sortie.SortieAugmentation_MOD_STATS_BY_AIRCRAFT.fixed_captures = True sortie.SortieAugmentation_MOD_STATS_BY_AIRCRAFT.save() def log_update(self, to_compute): - return '[mod_stats_by_aircraft]: Fixing capture stats. {} sorties left to process.' .format(to_compute) + return '[mod_stats_by_aircraft]: Fixing capture stats. {} sorties left to process.'.format(to_compute) def log_done(self): return '[mod_stats_by_aircraft]: Completed fixing capture stats.'