Add cron job to update list of blink components

This commit is contained in:
Eric Bidelman 2017-06-20 21:03:49 -07:00
Родитель 5a525734d1
Коммит 97ba7e5b10
3 изменённых файлов: 14 добавлений и 3 удалений

Просмотреть файл

@ -190,7 +190,7 @@ class HistogramsHandler(webapp2.RequestHandler):
def get(self):
# Attempt to fetch enums mapping file.
result = urlfetch.fetch(HISTOGRAMS_URL)
result = urlfetch.fetch(HISTOGRAMS_URL, deadline=60)
if (result.status_code != 200):
logging.error('Unable to retrieve chromium histograms mapping file.')
@ -427,9 +427,18 @@ class FeatureHandler(common.ContentHandler):
return self.redirect(redirect_url)
class BlinkComponentHandler(webapp2.RequestHandler):
"""Updates the list of Blink components in the db."""
def get(self):
models.BlinkComponent.update_db()
self.response.out.write('Blink components updated')
app = webapp2.WSGIApplication([
('/cron/metrics', YesterdayHandler),
('/cron/histograms', HistogramsHandler),
('/cron/update_blink_components', BlinkComponentHandler),
('/(.*)/([0-9]*)', FeatureHandler),
('/(.*)', FeatureHandler),
], debug=settings.DEBUG)

Просмотреть файл

@ -5,3 +5,6 @@ cron:
- description: retrieve from UMA Cloud Storage data gathered yesterday
url: /cron/metrics
schedule: every day 22:00
- desription: update list of Blink components
url: /cron/update_blink_components
schedule: every day 04:30

Просмотреть файл

@ -236,7 +236,7 @@ class BlinkComponent(DictModel):
components = memcache.get(key)
if components is None or update_cache:
components = []
result = urlfetch.fetch(self.COMPONENTS_URL)
result = urlfetch.fetch(self.COMPONENTS_URL, deadline=60)
if result.status_code == 200:
components = sorted(json.loads(result.content))
memcache.set(key, components)
@ -250,7 +250,6 @@ class BlinkComponent(DictModel):
for name in new_components:
if not len([x.name for x in existing_comps if x.name == name]):
logging.info('Adding new BlinkComponent: ' + name)
print 'Adding new BlinkComponent: ' + name
c = BlinkComponent(name=name)
c.put()