donate-cpu.py: Improve upload error handling, remove old "fast" code.
If an upload fails, the reason (exception text) is now printed. Fix: If the last retry failed do not wait until continuing. Remove some obsolete "fast" code in the uploadResults() function. Tested with Python 2.7.16 and Python 3.6.8.
This commit is contained in:
parent
f5cb289b7d
commit
6b9a25869e
|
@ -40,7 +40,7 @@ import platform
|
||||||
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
|
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
|
||||||
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
|
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
|
||||||
# changes)
|
# changes)
|
||||||
CLIENT_VERSION = "1.1.18"
|
CLIENT_VERSION = "1.1.19"
|
||||||
|
|
||||||
|
|
||||||
def checkRequirements():
|
def checkRequirements():
|
||||||
|
@ -372,28 +372,29 @@ def sendAll(connection, data):
|
||||||
|
|
||||||
def uploadResults(package, results, server_address):
|
def uploadResults(package, results, server_address):
|
||||||
print('Uploading results..')
|
print('Uploading results..')
|
||||||
for retry in range(4):
|
max_retries = 4
|
||||||
|
for retry in range(max_retries):
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect(server_address)
|
sock.connect(server_address)
|
||||||
if results.startswith('FAST'):
|
cmd = 'write\n'
|
||||||
cmd = 'write-fast\n'
|
|
||||||
else:
|
|
||||||
cmd = 'write\n'
|
|
||||||
sendAll(sock, cmd + package + '\n' + results + '\nDONE')
|
sendAll(sock, cmd + package + '\n' + results + '\nDONE')
|
||||||
sock.close()
|
sock.close()
|
||||||
print('Results have been successfully uploaded.')
|
print('Results have been successfully uploaded.')
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error as err:
|
||||||
print('Upload failed, retry in 30 seconds')
|
print('Upload error: ' + str(err))
|
||||||
time.sleep(30)
|
if retry < (max_retries - 1):
|
||||||
|
print('Retrying upload in 30 seconds')
|
||||||
|
time.sleep(30)
|
||||||
print('Upload permanently failed!')
|
print('Upload permanently failed!')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def uploadInfo(package, info_output, server_address):
|
def uploadInfo(package, info_output, server_address):
|
||||||
print('Uploading information output..')
|
print('Uploading information output..')
|
||||||
for retry in range(3):
|
max_retries = 3
|
||||||
|
for retry in range(max_retries):
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect(server_address)
|
sock.connect(server_address)
|
||||||
|
@ -401,9 +402,11 @@ def uploadInfo(package, info_output, server_address):
|
||||||
sock.close()
|
sock.close()
|
||||||
print('Information output has been successfully uploaded.')
|
print('Information output has been successfully uploaded.')
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error as err:
|
||||||
print('Upload failed, retry in 30 seconds')
|
print('Upload error: ' + str(err))
|
||||||
time.sleep(30)
|
if retry < (max_retries - 1):
|
||||||
|
print('Retrying upload in 30 seconds')
|
||||||
|
time.sleep(30)
|
||||||
print('Upload permanently failed!')
|
print('Upload permanently failed!')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue