Skip to content

Instantly share code, notes, and snippets.

@arikfr
Created July 22, 2016 11:40
Show Gist options
  • Save arikfr/c86366ce55b79842cb7c76fcedf01496 to your computer and use it in GitHub Desktop.
Save arikfr/c86366ce55b79842cb7c76fcedf01496 to your computer and use it in GitHub Desktop.
Example code of how to use Redash refresh API
REDASH_HOST = os.environ.get('REDASH_HOST', 'https://app.redash.io/name')
def poll_job(s, job):
# TODO: timeout
while job['status'] not in (3,4):
response = s.get('{}/api/jobs/{}'.format(REDASH_HOST, job['id']))
job = response.json()['job']
time.sleep(1)
return job['status'] == 3
def get_fresh_query_result(query_id, api_key):
s = requests.Session()
s.headers.update({'Authorization': 'Key {}'.format(api_key)})
response = s.post('{}/api/queries/{}/refresh'.format(REDASH_HOST, query_id))
if response.status_code != 200:
raise Exception('Refresh failed.')
# TODO: make sure it's true.
poll_job(s, response.json()['job'])
response = s.get('{}/api/queries/{}/results.json'.format(REDASH_HOST, query_id))
if response.status_code != 200:
raise Exception('Failed getting results.')
return response.json()['query_result']['data']['rows']
@kirollosHossam
Copy link

hello arik ,
actually i got job['status']=1 , so do you recommend what is the issue here to get this value ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment