test-my-pr: Retry if failed to get package (#2515)

This commit is contained in:
Rikard Falkeborn 2020-02-02 18:00:36 +01:00 committed by GitHub
parent bbfd10a69f
commit 0d361f8a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 21 deletions

View File

@ -160,10 +160,6 @@ while True:
package = package_url
else:
package = get_package(server_address)
while len(package) == 0:
print("network or server might be temporarily down.. will try again in 30 seconds..")
time.sleep(30)
package = get_package(server_address)
tgz = download_package(work_path, package, bandwidth_limit)
if tgz is None:
print("No package downloaded")

View File

@ -135,20 +135,21 @@ def get_packages_count(server_address):
def get_package(server_address, package_index=None):
print('Connecting to server to get assigned work..')
package = b''
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(server_address)
if package_index is None:
sock.send(b'get\n')
else:
request = 'getPackageIdx:' + str(package_index) + '\n'
sock.send(request.encode())
package = sock.recv(256)
except socket.error:
pass
sock.close()
while not package:
print('Connecting to server to get assigned work..')
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect(server_address)
if package_index is None:
sock.send(b'get\n')
else:
request = 'getPackageIdx:' + str(package_index) + '\n'
sock.send(request.encode())
package = sock.recv(256)
except socket.error:
print("network or server might be temporarily down.. will try again in 30 seconds..")
time.sleep(30)
return package.decode('utf-8')

View File

@ -9,7 +9,6 @@ import argparse
import os
import sys
import random
import time
import subprocess
if __name__ == "__main__":
@ -73,9 +72,6 @@ if __name__ == "__main__":
while packages_processed < args.p and len(packages_idxs) > 0:
package = lib.get_package(lib.server_address, packages_idxs.pop())
if len(package) == 0:
print("network or server might be temporarily down..")
sys.exit(1)
tgz = lib.download_package(work_path, package, None)
if tgz is None: