From 2ec1e7e69df9e3797eda5c38693aebaf71f32637 Mon Sep 17 00:00:00 2001 From: shlurbee Date: Tue, 24 Jul 2012 15:28:45 -0700 Subject: [PATCH] Error handling in promote.get_scheduled Aggressively catches and logs exceptions inside the campaign loop in get_scheduled. This change will allow make_daily_promotions to skip over campaigns with corrupt data and still launch the others. Note: We might want to consider passing the list of errored campaigns back up to the calling function so they can be handled more noisily there. --- r2/r2/lib/promote.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/r2/r2/lib/promote.py b/r2/r2/lib/promote.py index 5c369dca1..fb3e31119 100644 --- a/r2/r2/lib/promote.py +++ b/r2/r2/lib/promote.py @@ -652,9 +652,17 @@ def accepted_campaigns(offset=0): def get_scheduled(offset=0): by_sr = {} + failed = [] for l, campaign, weight in accepted_campaigns(offset=offset): - if authorize.is_charged_transaction(campaign.trans_id, campaign._id): - by_sr.setdefault(campaign.sr_name, []).append((l, weight)) + try: + if authorize.is_charged_transaction(campaign.trans_id, campaign._id): + by_sr.setdefault(campaign.sr_name, []).append((l, weight)) + except Exception, e: # could happen if campaign things have corrupt data + failed.append((campaign._id, e)) + if failed: + err_msgs = ["camp id: %d, reason: %r" % (f[0], f[1]) for f in failed] + g.log.error("%d accepted campaign not included in schedule:\n%s" % + (len(failed), "\n".join(err_msgs))) return by_sr