Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Make TSV export job log errors but handle them gracefully. Bug 660859.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Wenzel committed May 31, 2011
1 parent d5d4f3c commit c1bc361
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions apps/api/cron.py
@@ -1,11 +1,12 @@
from time import mktime
import bz2
import csv
import os.path
import shutil
from time import mktime

from django.conf import settings

import commonware.log
import cronjobs

from input import PRODUCT_IDS
Expand All @@ -14,6 +15,7 @@


BUCKET_SIZE = 10000 # Bucket size to split query set into.
log = commonware.log.getLogger('i.export_tsv')


class TSVDialect(csv.Dialect):
Expand Down Expand Up @@ -65,19 +67,23 @@ def export_tsv():
tsv = csv.writer(outfile, dialect=TSVDialect)
for bucket in _split_queryset(opinions):
for opinion in bucket:
tsv.writerow(_fix_row([
opinion.id,
int(mktime(opinion.created.timetuple())),
OPINION_TYPES.get(opinion.type).short,
getattr(PRODUCT_IDS.get(opinion.product), 'short', None),
opinion.version,
opinion.platform,
opinion.locale,
opinion.manufacturer,
opinion.device,
opinion.url,
opinion.description,
]))
try:
tsv.writerow(_fix_row([
opinion.id,
int(mktime(opinion.created.timetuple())),
getattr(OPINION_TYPES.get(opinion.type), 'short', None),
getattr(PRODUCT_IDS.get(opinion.product), 'short', None),
opinion.version,
opinion.platform,
opinion.locale,
opinion.manufacturer,
opinion.device,
opinion.url,
opinion.description,
]))
except Exception, e:
log.warning('Error exporting opinion %d: %s' % (
opinion.id, str(e)))
finally:
outfile.close()
shutil.move(opinions_tmp, opinions_path)
Expand Down

0 comments on commit c1bc361

Please sign in to comment.