in crashes.py [0:0]
def getRedashQueryResult(redash_url, query_id, api_key, cacheValue, params):
s = requests.Session()
s.headers.update({'Authorization': 'Key {}'.format(api_key)})
# max_age is a redash value that controls cached results. If there is a cached query result
# newer than this time (in seconds) it will be returned instead of a fresh query.
# 86400 = 24 hours, 43200 = 12 hours, 0 = refresh query
#
# Note sometimes the redash caching feature gets 'stuck' on an old cache. Side effect is
# that all reports will eventually be older than 7 days and as such will be filtered out
# by this script's age checks in processRedashDataset. Crash lists will shrink to zero
# as a result.
payload = dict(max_age=cacheValue, parameters=params)
url = "%s/api/queries/%s/results" % (redash_url, query_id)
response = s.post(url, data=json.dumps(payload))
if response.status_code != 200:
print("\nquery error '%s'" % response)
pp.pprint(payload)
raise Exception('Redash query failed.')
#{ 'job': { 'error': '',
# 'id': '21429857-5fd0-443d-ba4b-fb9cc6d49add',
# 'query_result_id': None,
# 'result': None,
# 'status': 1,
# 'updated_at': 0}}
# ...or, we just get back the result
try:
result = response.json()['job']
except KeyError:
return response.json()
result_id = poll_job(s, redash_url, response.json()['job'])
response = s.get('{}/api/queries/{}/results/{}.json'.format(redash_url, query_id, result_id))
if response.status_code != 200:
raise Exception('Failed getting results. (Check your redash query for errors.) statuscode=%d' % response.status_code)
return response.json()