File tree 1 file changed +7
-4
lines changed 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 4
4
import hashlib
5
5
import json
6
6
import os
7
+ import random
7
8
import re
8
9
import subprocess
9
10
import sys
@@ -164,16 +165,18 @@ def get_externals() -> list[str]:
164
165
165
166
166
167
def download_with_retries (download_location : str ,
167
- max_retries : int = 5 ,
168
- base_delay : float = 2.0 ) -> typing .Any :
168
+ max_retries : int = 7 ,
169
+ base_delay : float = 2.25 ,
170
+ max_jitter : float = 1.0 ) -> typing .Any :
169
171
"""Download a file with exponential backoff retry."""
170
172
for attempt in range (max_retries ):
171
173
try :
172
174
resp = urllib .request .urlopen (download_location )
173
175
except urllib .error .URLError as ex :
174
176
if attempt == max_retries :
175
- raise ex
176
- time .sleep (base_delay ** attempt )
177
+ msg = f"Download from { download_location } failed."
178
+ raise OSError (msg ) from ex
179
+ time .sleep (base_delay ** attempt + random .uniform (0 , max_jitter ))
177
180
else :
178
181
return resp
179
182
You can’t perform that action at this time.
0 commit comments