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.
This commit is contained in:
shlurbee
2012-07-24 15:28:45 -07:00
committed by bsimpson63
parent cbb072c75b
commit 2ec1e7e69d

View File

@@ -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