mirror of
https://github.com/netzbegruenung/green-spider-api.git
synced 2024-05-03 17:23:40 +02:00
Adapt LastUpdated to use ES
This commit is contained in:
parent
0600480db3
commit
110a3c0ac0
15
main.py
15
main.py
|
@ -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']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue