From a972551e1bf25ecd5b99dcf58d27dd18b8623332 Mon Sep 17 00:00:00 2001 From: Brian Simpson Date: Wed, 21 Aug 2013 09:34:20 -0400 Subject: [PATCH] Hook fires on each new charge, not once for entire charge_pending. --- r2/r2/lib/promote.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/r2/r2/lib/promote.py b/r2/r2/lib/promote.py index ce778f95e..b263304df 100644 --- a/r2/r2/lib/promote.py +++ b/r2/r2/lib/promote.py @@ -568,10 +568,18 @@ def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: - if (authorize.is_charged_transaction(camp.trans_id, camp._id) or not - authorize.charge_transaction(user, camp.trans_id, camp._id)): + if authorize.is_charged_transaction(camp.trans_id, camp._id): + # already charged continue + charge_succeeded = authorize.charge_transaction(user, camp.trans_id, + camp._id) + + if not charge_succeeded: + continue + + hooks.get_hook('promote.new_charge').call(link=l, campaign=camp) + if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: @@ -583,8 +591,6 @@ def charge_pending(offset=1): except: print "Error on %s, campaign %s" % (l, camp._id) - hooks.get_hook('promote.charge_pending').call(offset=offset) - def scheduled_campaigns_by_link(l, date=None): # A promotion/campaign is scheduled/live if it's in