Skip to content

Commit

Permalink
Print backtrace if washing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrrgc committed Jan 26, 2014
1 parent f789725 commit af46f72
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions management/commands/wash.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from django.core.management.base import BaseCommand, CommandError

from lasana.models import Meal
Expand All @@ -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("----------------------------------------")

0 comments on commit af46f72

Please sign in to comment.