Skip to content

Commit

Permalink
Error handling in promote.get_scheduled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shlurbee authored and bsimpson63 committed Jul 25, 2012
1 parent cbb072c commit 2ec1e7e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions r2/r2/lib/promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 2ec1e7e

Please sign in to comment.