ads: Add endpoint for health check on ads

Adds a new route /health/ads which returns in plain text the seconds
since the epoch that the ad system was last updated via make_daily_promotions()
This commit is contained in:
Keith Mitchell
2012-10-25 13:08:36 -07:00
committed by bsimpson63
parent 82014d80b1
commit 81891ea4d7
3 changed files with 19 additions and 0 deletions

View File

@@ -158,6 +158,7 @@ def make_map():
mc('/promoted/', controller='promoted', action="listing", sort="")
mc('/health', controller='health', action='health')
mc('/health/ads', controller='health', action='promohealth')
mc('/', controller='hot', action='listing')

View File

@@ -30,6 +30,7 @@ from pylons import c, g, response
from reddit_base import MinimalController
from r2.lib.amqp import worker
from r2.lib import promote
from validator import *
@@ -47,3 +48,7 @@ class HealthController(MinimalController):
c.dontcache = True
response.headers['Content-Type'] = 'text/plain'
return json.dumps(g.versions, sort_keys=True, indent=4)
def GET_promohealth(self):
response.headers['Content-Type'] = 'text/plain'
return json.dumps(promote.health_check())

View File

@@ -23,9 +23,11 @@
from __future__ import with_statement
import json
import time
from r2.models import *
from r2.models.bidding import SponsorBoxWeightings, WeightingRef
from r2.models.keyvalue import NamedGlobals
from r2.lib.wrapped import Wrapped
from r2.lib import authorize
from r2.lib import emailer, filters
@@ -54,6 +56,16 @@ CAMPAIGN = Enum("start", "end", "bid", "sr", "trans_id")
UPDATE_QUEUE = 'update_promos_q'
QUEUE_ALL = 'all'
PROMO_HEALTH_KEY = 'promotions_last_updated'
def _mark_promos_updated():
NamedGlobals.set(PROMO_HEALTH_KEY, time.time())
def health_check():
return NamedGlobals.get(PROMO_HEALTH_KEY, default=0)
@memoize("get_promote_srid")
def get_promote_srid(name = 'promos'):
@@ -831,6 +843,7 @@ def make_daily_promotions(offset = 0, test = False):
if not test:
set_live_promotions(all_links, weighted)
_mark_promos_updated()
else:
print (all_links, weighted)