Flaky CI seems to fail to download sometimes
This commit is contained in:
parent
d29b0ebcfd
commit
1a77b32e01
1 changed files with 27 additions and 1 deletions
|
|
@ -33,6 +33,8 @@ import tarfile
|
||||||
import hashlib
|
import hashlib
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import functools
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from io import BytesIO ## for Python 3
|
from io import BytesIO ## for Python 3
|
||||||
|
|
@ -352,6 +354,30 @@ def InstallNodeDebug( name, root ):
|
||||||
MakeSymlink( gadget_dir, name, root )
|
MakeSymlink( gadget_dir, name, root )
|
||||||
|
|
||||||
|
|
||||||
|
def WithRetry( f ):
|
||||||
|
retries = 5
|
||||||
|
timeout = 1 # seconds
|
||||||
|
|
||||||
|
@functools.wraps( f )
|
||||||
|
def wrapper( *args, **kwargs ):
|
||||||
|
thrown = None
|
||||||
|
for _ in range( retries ):
|
||||||
|
try:
|
||||||
|
return f( *args, **kwargs )
|
||||||
|
except Exception as e:
|
||||||
|
thrown = e
|
||||||
|
print( "Failed - {}, will retry in {} seconds".format( e, timeout ) )
|
||||||
|
time.sleep( timeout )
|
||||||
|
raise thrown
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@WithRetry
|
||||||
|
def UrlOpen( *args, **kwargs ):
|
||||||
|
return urllib2.urlopen( *args, **kwargs )
|
||||||
|
|
||||||
|
|
||||||
def DownloadFileTo( url, destination, file_name = None, checksum = None ):
|
def DownloadFileTo( url, destination, file_name = None, checksum = None ):
|
||||||
if not file_name:
|
if not file_name:
|
||||||
file_name = url.split( '/' )[ -1 ]
|
file_name = url.split( '/' )[ -1 ]
|
||||||
|
|
@ -377,7 +403,7 @@ def DownloadFileTo( url, destination, file_name = None, checksum = None ):
|
||||||
|
|
||||||
print( "Downloading {} to {}/{}".format( url, destination, file_name ) )
|
print( "Downloading {} to {}/{}".format( url, destination, file_name ) )
|
||||||
|
|
||||||
with contextlib.closing( urllib2.urlopen( r ) ) as u:
|
with contextlib.closing( UrlOpen( r ) ) as u:
|
||||||
with open( file_path, 'wb' ) as f:
|
with open( file_path, 'wb' ) as f:
|
||||||
f.write( u.read() )
|
f.write( u.read() )
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue