Adapt LastUpdated to use ES

This commit is contained in:
Marian Steinbach 2019-04-12 09:15:14 +02:00
parent 0600480db3
commit 110a3c0ac0

15
main.py
View file

@ -122,17 +122,14 @@ class LastUpdated(object):
""" """
Informs about the most recent update to the spider results data Informs about the most recent update to the spider results data
""" """
query = datastore_client.query(kind=spider_results_kind, res = es.search(index=es_index_name,
order=['-created'], filter_path=['hits.hits._source.created'],
projection=['created']) body={"query": {"match_all": {}}},
items = list(query.fetch(limit=1, eventual=True)) sort='created:desc',
ts = int(items[0].get('created')) / 1000000 size=1)
dt = datetime.utcfromtimestamp(ts).isoformat()
maxage = 60 * 60 # one hour in seconds
resp.cache_control = ["max_age=%d" % maxage]
resp.media = { resp.media = {
"last_updated": dt "last_updated": res['hits']['hits'][0]['_source']['created']
} }