-
Notifications
You must be signed in to change notification settings - Fork 1
/
rave-tutorial-retrieve-multi.py
70 lines (54 loc) · 1.65 KB
/
rave-tutorial-retrieve-multi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from pkg_resources import parse_version
import requests
import pyvo as vo
import pandas as pd
from pyvo.dal.tap import AsyncTAPJob
#
# Verify the version of pyvo
#
if parse_version(vo.__version__) < parse_version('1.0'):
raise ImportError('pyvo version must larger than 1.0')
print('\npyvo version {version} \n'.format(version=vo.__version__))
#
# Setup tap_service
#
service_name = 'rave-survey.org'
url = "https://www.rave-survey.org/tap"
token = 'Token <your-token>'
# Setup authorization
tap_session = requests.Session()
tap_session.headers['Authorization'] = token
# tap_service = vo.dal.TAPService(url, session=tap_session) # rmrk: this is not needed
partial_results = []
running_job_names = []
#
# Recreate the job from url and session (token)
#
# read the url
with open('jobs_url.txt', 'r') as fd:
job_urls = fd.readlines()
# reopen the file to store the non finished jobs
fd = open('jobs_url.txt', 'w')
for job_url in job_urls:
# recreate the job
job = AsyncTAPJob(job_url, session=tap_session)
#
# Check the job status
#
print('JOB {name}: {status}'.format(name=job.job.runid , status=job.phase))
# if still running --> exit
if job.phase not in ("COMPLETED", "ERROR", "ABORTED"):
running_job_names.append(job.job.runid)
fd.write(job_url)
continue
#
# Fetch the results
#
job.raise_if_error() # This need to be caught!!
print('fetching the results...\n')
partial_results.append(job.fetch_result())
print('...DONE\n')
try:
assert(running_job_names == [])
except AssertionError:
print("The following jobs are still executing: {}".format(running_job_names))