File tree Expand file tree Collapse file tree 2 files changed +22
-20
lines changed Expand file tree Collapse file tree 2 files changed +22
-20
lines changed Original file line number Diff line number Diff line change 13
13
import warnings
14
14
15
15
import requests
16
+ import tenacity
16
17
17
18
from firefox_code_coverage import taskcluster
18
19
@@ -67,29 +68,29 @@ def _save_tasks(response):
67
68
return tasks
68
69
69
70
70
- def download_binary (url , path , retries = 5 ):
71
+ @tenacity .retry (
72
+ stop = tenacity .stop_after_attempt (5 ),
73
+ wait = tenacity .wait_incrementing (start = 7 , increment = 7 ),
74
+ reraise = True ,
75
+ )
76
+ def download_binary (url , path ):
71
77
"""Download a binary file from an url"""
72
- for i in range (1 , retries + 1 ):
78
+
79
+ try :
80
+ artifact = requests .get (url , stream = True )
81
+ artifact .raise_for_status ()
82
+
83
+ with open (path , "wb" ) as f :
84
+ for chunk in artifact .iter_content (chunk_size = 8192 ):
85
+ f .write (chunk )
86
+
87
+ except Exception :
73
88
try :
74
- artifact = requests .get (url , stream = True )
75
- artifact .raise_for_status ()
76
-
77
- with open (path , "wb" ) as f :
78
- for chunk in artifact .iter_content (chunk_size = 8192 ):
79
- f .write (chunk )
80
- break
81
- except : # noqa: E722
82
- try :
83
- os .remove (path )
84
- except OSError :
85
- pass
86
-
87
- if i == retries :
88
- raise Exception (
89
- "Download failed after {} retries - {}" .format (retries , url )
90
- )
89
+ os .remove (path )
90
+ except OSError :
91
+ pass
91
92
92
- time . sleep ( 7 * i )
93
+ raise
93
94
94
95
95
96
def download_artifact (task_id , artifact , artifacts_path ):
Original file line number Diff line number Diff line change 1
1
taskcluster == 24.2.0
2
+ tenacity == 6.0.0
You can’t perform that action at this time.
0 commit comments