Commit f7435caf7de46515916c0092145fbd80012ab4f6

Authored by Sergio Oliveira
2 parents dcbb8462 51f49c61

Merge pull request #49 from colab/log_scripts

Logged expection in import_email script
src/badger/management/commands/update_badges.py
... ... @@ -6,11 +6,12 @@ from haystack.query import SearchQuerySet
6 6 from accounts.models import User
7 7 from badger.models import Badge
8 8  
  9 +import logging
9 10  
10 11 class Command(BaseCommand):
11 12 help = "Update the user's badges"
12 13  
13   - def handle(self, *args, **kwargs):
  14 + def update_badges(self):
14 15 for badge in Badge.objects.filter(type='auto'):
15 16 if not badge.comparison:
16 17 continue
... ... @@ -30,10 +31,14 @@ class Command(BaseCommand):
30 31 )
31 32 opts = {key: badge.value}
32 33  
33   - sqs = SearchQuerySet().filter(
34   - type='user',
35   - **opts
36   - )
  34 + sqs = SearchQuerySet().filter(type='user', **opts)
37 35  
38 36 for user in sqs:
39 37 badge.awardees.add(User.objects.get(pk=user.pk))
  38 +
  39 + def handle(self, *args, **kwargs):
  40 + try:
  41 + self.update_badges()
  42 + except Exception as e:
  43 + logging.exception(e)
  44 + raise
... ...
src/super_archives/management/commands/import_emails.py
... ... @@ -7,6 +7,7 @@ import os
7 7 import re
8 8 import sys
9 9 import mailbox
  10 +import logging
10 11 from optparse import make_option
11 12  
12 13 from django.db import transaction
... ... @@ -248,7 +249,6 @@ class Command(BaseCommand, object):
248 249 # This anti-pattern is needed to avoid the transations to
249 250 # get stuck in case of errors.
250 251 transaction.rollback()
251   - os.remove(self.lock_file)
252 252 raise
253 253  
254 254 count += 1
... ... @@ -279,8 +279,12 @@ class Command(BaseCommand, object):
279 279 run_lock = file(self.lock_file, 'w')
280 280 run_lock.close()
281 281  
282   - self.import_emails(archives_path,
  282 + try:
  283 + self.import_emails(archives_path,
283 284 options.get('all'), options.get('exclude_lists'))
284   -
285   - os.remove(self.lock_file)
  285 + except Exception as e:
  286 + logging.exception(e)
  287 + raise
  288 + finally:
  289 + os.remove(self.lock_file)
286 290  
... ...