def update_event_fires_for_campaign(campaign_id): # get a lock r = get_redis_connection() key = 'event_fires_campaign_%d' % campaign_id with r.lock(key, timeout=300): try: with transaction.atomic(): campaign = Campaign.objects.filter(pk=campaign_id).first() if campaign: EventFire.do_update_campaign_events(campaign) except Exception as e: # requeue our task to try again in five minutes update_event_fires_for_campaign(campaign_id).delay(countdown=60*5) # bubble up the exception so sentry sees it raise e