From af46f72f67008c3da5cf380189efaa2a0505692f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Boya=20Garc=C3=ADa?= Date: Sun, 26 Jan 2014 01:38:14 +0100 Subject: [PATCH] Print backtrace if washing fails --- management/commands/wash.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) 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("----------------------------------------")