diff --git a/management/commands/wash.py b/management/commands/wash.py index 594b3ac..5ca4c9d 100644 --- a/management/commands/wash.py +++ b/management/commands/wash.py @@ -1,3 +1,4 @@ +from __future__ import print_function from django.core.management.base import BaseCommand, CommandError from lasana.models import Meal @@ -9,14 +10,22 @@ class Command(BaseCommand): help = 'Deletes expired meals' def handle(self, *args, **options): - now = timezone.now() - old_meals = Meal.objects.all().order_by("expiration_time") + try: + now = timezone.now() + old_meals = Meal.objects.all().order_by("expiration_time") - for meal in old_meals: - if meal.is_expired(now): - meal_id = meal.id + for meal in old_meals: + if meal.is_expired(now): + meal_id = meal.id - meal.delete() - self.stdout.write('Thrown away expired meal "%s"\n' % meal_id) - else: - break + meal.delete() + self.stdout.write('Thrown away expired meal "%s"\n' % meal_id) + else: + break + except: + import traceback + import sys + print("----------------------------------------") + print("Failed to wash meals.", file=sys.stderr) + traceback.print_exc(sys.stderr) + print("----------------------------------------")