Skip to content

Commit fb38b1b

Browse files
author
David Shiga
authored
Improve retry logging and restrict dependencies to a single major version (807). (#57)
1 parent 841d0c0 commit fb38b1b

File tree

6 files changed

+49
-38
lines changed

6 files changed

+49
-38
lines changed

adapter_pipelines/submit.wdl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ task stage_files {
133133
export PYTHONUNBUFFERED=TRUE
134134
135135
# Get the urn needed for staging files
136-
staging_urn=$(get-staging-urn --envelope_url ${submission_url})
136+
get-upload-urn -envelope_url ${submission_url} -output upload_urn.txt
137+
upload_urn=$(cat upload_urn.txt)
137138
138-
# Select staging area
139-
echo "hca upload select $staging_urn"
140-
hca upload select $staging_urn
139+
# Select upload area
140+
echo "hca upload select $upload_urn"
141+
hca upload select $upload_urn
141142
142143
# Stage the files
143144
files=( ${sep=' ' files} )

pipeline_tools/confirm_submission.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
from tenacity import retry_if_result, RetryError
5+
from datetime import datetime
56
from pipeline_tools.http_requests import HttpRequests
67

78

@@ -22,7 +23,8 @@ def wait_for_valid_status(envelope_url, http_requests):
2223
tenacity.RetryError: if status is invalid past timeout
2324
"""
2425
def log_before(envelope_url):
25-
print('Getting status for {}'.format(envelope_url))
26+
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
27+
print('{0} Getting status for {1}'.format(now, envelope_url))
2628

2729
def status_is_invalid(response):
2830
envelope_js = response.json()
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22

33
import argparse
44
from tenacity import retry_if_result, RetryError
5+
from datetime import datetime
56
from pipeline_tools.http_requests import HttpRequests
67

78

89
def run(envelope_url, http_requests):
9-
"""Check the contents of the submission envelope for the staging urn. Retry until the envelope contains a
10-
staging urn, or if there is an error with the request.
10+
"""Check the contents of the submission envelope for the upload urn. Retry until the envelope contains a
11+
upload urn, or if there is an error with the request.
1112
1213
Args:
1314
http_requests (HttpRequests): an HttpRequests object.
1415
envelope_url (str): the submission envelope url
1516
1617
Returns:
17-
String giving the staging urn in the format dcp:upl:aws:integration:12345:abcde
18+
String giving the upload urn in the format dcp:upl:aws:integration:12345:abcde
1819
1920
Raises:
2021
requests.HTTPError: for 4xx errors or 5xx errors beyond timeout
2122
tenacity.RetryError: if urn is missing beyond timeout
2223
"""
2324
def urn_is_none(response):
2425
envelope_js = response.json()
25-
urn = get_staging_urn(envelope_js)
26+
urn = get_upload_urn(envelope_js)
27+
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
28+
print('{0} Upload urn: {1}'.format(now, urn))
2629
return urn is None
2730

2831
response = (
@@ -32,18 +35,18 @@ def urn_is_none(response):
3235
retry=retry_if_result(urn_is_none)
3336
)
3437
)
35-
urn = get_staging_urn(response.json())
38+
urn = get_upload_urn(response.json())
3639
return urn
3740

3841

39-
def get_staging_urn(envelope_js):
40-
"""Get the staging urn from the submission envelope.
42+
def get_upload_urn(envelope_js):
43+
"""Get the upload urn from the submission envelope.
4144
4245
Args:
4346
envelope_js (dict): the submission envelope contents
4447
4548
Returns:
46-
String giving the staging urn in the format dcp:upl:aws:integration:12345:abcde,
49+
String giving the upload urn in the format s3://<bucket>/<uuid>,
4750
or None if the envelope doesn't contain a urn
4851
"""
4952
details = envelope_js.get('stagingDetails')
@@ -58,14 +61,16 @@ def get_staging_urn(envelope_js):
5861

5962
def main():
6063
parser = argparse.ArgumentParser()
61-
parser.add_argument('--envelope_url', required=True)
64+
parser.add_argument('-envelope_url', required=True)
65+
parser.add_argument('-output', default='upload_urn.txt')
6266
args = parser.parse_args()
6367
try:
6468
urn = run(args.envelope_url, HttpRequests())
6569
except RetryError:
6670
message = 'Timed out while trying to get urn.'
6771
raise ValueError(message)
68-
print(urn)
72+
with open('upload_urn.txt', 'w') as f:
73+
f.write(urn)
6974

7075

7176
if __name__ == '__main__':

pipeline_tools/http_requests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import glob
55
from tenacity import retry, stop_after_attempt, stop_after_delay, wait_exponential, retry_if_exception
6+
from datetime import datetime
67

78

89
HTTP_RECORD_DIR = 'HTTP_RECORD_DIR'
@@ -140,6 +141,8 @@ def post(self, *args, **kwargs):
140141

141142
def _http_request_with_retry(self, *args, **kwargs):
142143
def is_retryable(error):
144+
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
145+
print('{0} {1}'.format(now, repr(error)))
143146
def is_retryable_status_code(error):
144147
return isinstance(error, requests.HTTPError) and not (400 <= error.response.status_code <= 499)
145148
return is_retryable_status_code(error) or isinstance(error,

pipeline_tools/tests/test_get_staging_urn.py renamed to pipeline_tools/tests/test_get_upload_urn.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import requests
33
import requests_mock
4-
import pipeline_tools.get_staging_urn as gsu
4+
import pipeline_tools.get_upload_urn as getter
55
from .http_requests_manager import HttpRequestsManager
66
from pipeline_tools.http_requests import HttpRequests
77
from tenacity import RetryError
@@ -19,36 +19,36 @@ def setUp(self):
1919
}
2020
}
2121

22-
def test_get_staging_urn_empty_js(self):
22+
def test_get_upload_urn_empty_js(self):
2323
js = {}
24-
self.assertIsNone(gsu.get_staging_urn(js))
24+
self.assertIsNone(getter.get_upload_urn(js))
2525

26-
def test_get_staging_urn_null_details(self):
26+
def test_get_upload_urn_null_details(self):
2727
js = {
2828
'stagingDetails': None
2929
}
30-
self.assertIsNone(gsu.get_staging_urn(js))
30+
self.assertIsNone(getter.get_upload_urn(js))
3131

32-
def test_get_staging_urn_null_location(self):
32+
def test_get_upload_urn_null_location(self):
3333
js = {
3434
'stagingDetails': {
3535
'stagingAreaLocation': None
3636
}
3737
}
38-
self.assertIsNone(gsu.get_staging_urn(js))
38+
self.assertIsNone(getter.get_upload_urn(js))
3939

40-
def test_get_staging_urn_null_value(self):
40+
def test_get_upload_urn_null_value(self):
4141
js = {
4242
'stagingDetails': {
4343
'stagingAreaLocation': {
4444
'value': None
4545
}
4646
}
4747
}
48-
self.assertIsNone(gsu.get_staging_urn(js))
48+
self.assertIsNone(getter.get_upload_urn(js))
4949

50-
def test_get_staging_urn_valid_value(self):
51-
self.assertEqual(gsu.get_staging_urn(self.envelope_json), 'test_urn')
50+
def test_get_upload_urn_valid_value(self):
51+
self.assertEqual(getter.get_upload_urn(self.envelope_json), 'test_urn')
5252

5353
@requests_mock.mock()
5454
def test_run(self, mock_request):
@@ -57,7 +57,7 @@ def _request_callback(request, context):
5757
return self.envelope_json
5858
mock_request.get(self.envelope_url, json=_request_callback)
5959
with HttpRequestsManager():
60-
response = gsu.run(self.envelope_url, HttpRequests())
60+
response = getter.run(self.envelope_url, HttpRequests())
6161
self.assertEqual(mock_request.call_count, 1)
6262

6363
@requests_mock.mock()
@@ -67,7 +67,7 @@ def _request_callback(request, context):
6767
return {}
6868
mock_request.get(self.envelope_url, json=_request_callback)
6969
with self.assertRaises(RetryError), HttpRequestsManager():
70-
gsu.run(self.envelope_url, HttpRequests())
70+
getter.run(self.envelope_url, HttpRequests())
7171
self.assertEqual(mock_request.call_count, 3)
7272

7373
@requests_mock.mock()
@@ -77,7 +77,7 @@ def _request_callback(request, context):
7777
return {}
7878
mock_request.get(self.envelope_url, json=_request_callback)
7979
with self.assertRaises(requests.HTTPError), HttpRequestsManager():
80-
gsu.run(self.envelope_url, HttpRequests())
80+
getter.run(self.envelope_url, HttpRequests())
8181
self.assertEqual(mock_request.call_count, 3)
8282

8383
@requests_mock.mock()
@@ -87,7 +87,7 @@ def _request_callback(request, context):
8787
raise requests.ReadTimeout
8888
mock_request.get(self.envelope_url, json=_request_callback)
8989
with self.assertRaises(requests.ReadTimeout), HttpRequestsManager():
90-
gsu.run(self.envelope_url, HttpRequests())
90+
getter.run(self.envelope_url, HttpRequests())
9191
self.assertEqual(mock_request.call_count, 3)
9292

9393

setup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
packages=['pipeline_tools'],
1212
install_requires=[
1313
'cromwell-tools',
14-
'google-cloud-storage>=1.8.0',
15-
'hca>=4.0.0',
16-
'mock>=2.0.0',
17-
'requests>=2.18.4',
18-
'requests-mock>=1.4.0',
19-
'setuptools_scm==2.0.0',
20-
'tenacity>=4.10.0',
14+
'google-cloud-storage>=1.8.0,<2',
15+
'hca>=4.0.0,<5',
16+
'mock>=2.0.0,<3',
17+
'requests>=2.18.4,<3',
18+
'requests-mock>=1.4.0,<2',
19+
'setuptools_scm>=2.0.0,<3',
20+
'tenacity>=4.10.0,<5',
2121
],
2222
entry_points={
2323
"console_scripts": [
2424
'get-analysis-metadata=pipeline_tools.get_analysis_metadata:main',
2525
'create-analysis-json=pipeline_tools.create_analysis_json:main',
2626
'create-envelope=pipeline_tools.create_envelope:main',
27-
'get-staging-urn=pipeline_tools.get_staging_urn:main',
27+
'get-upload-urn=pipeline_tools.get_upload_urn:main',
2828
'confirm-submission=pipeline_tools.confirm_submission:main'
2929
]
3030
},

0 commit comments

Comments
 (0)