Automatically get a new machine ID when an error occurs
This commit is contained in:
1 parent
b1197bc2f0
commit
4fc6588414
1 file changed
+16
-15
+16
-15
@@ -29,16 +29,6 @@ OS_NAME = platform.system() + ' ' + platform.release()
|
|||||||
# Timeout for .get and .post requests (in seconds)
|
# Timeout for .get and .post requests (in seconds)
|
||||||
HTTP_TIMEOUT = 30
|
HTTP_TIMEOUT = 30
|
||||||
|
|
||||||
# Server tracks machines by IDs, which are saved
|
|
||||||
# locally once assigned. Regesitering a machine is
|
|
||||||
# not a problem, but creates junk in the database
|
|
||||||
try:
|
|
||||||
with open('machine.txt') as fin:
|
|
||||||
MACHINE_ID = int(fin.readlines()[0])
|
|
||||||
except:
|
|
||||||
MACHINE_ID = None
|
|
||||||
print('<Warning> Machine unregistered, will register with Server')
|
|
||||||
|
|
||||||
# Solution taken from Fishtest
|
# Solution taken from Fishtest
|
||||||
def killProcess(process):
|
def killProcess(process):
|
||||||
try:
|
try:
|
||||||
@@ -396,6 +386,14 @@ def completeWorkload(data):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
# Machine ID numbers are tracked by the server, and saved locally
|
||||||
|
try:
|
||||||
|
with open('machine.txt') as fin:
|
||||||
|
machineid = fin.readlines()[0]
|
||||||
|
except:
|
||||||
|
machineid = 'None'
|
||||||
|
print('<Warning> Machine unregistered, will register with Server')
|
||||||
|
|
||||||
# Download cutechess and any .dlls needed
|
# Download cutechess and any .dlls needed
|
||||||
getCoreFiles()
|
getCoreFiles()
|
||||||
|
|
||||||
@@ -405,7 +403,7 @@ if __name__ == '__main__':
|
|||||||
'password' : PASSWORD,
|
'password' : PASSWORD,
|
||||||
'threads' : THREADS,
|
'threads' : THREADS,
|
||||||
'osname' : OS_NAME,
|
'osname' : OS_NAME,
|
||||||
'machineid' : str(MACHINE_ID),
|
'machineid' : machineid,
|
||||||
}
|
}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -414,7 +412,7 @@ if __name__ == '__main__':
|
|||||||
# Request the information for the next workload
|
# Request the information for the next workload
|
||||||
request = requests.post('{0}/getWorkload/'.format(SERVER), data=postdata, timeout=HTTP_TIMEOUT)
|
request = requests.post('{0}/getWorkload/'.format(SERVER), data=postdata, timeout=HTTP_TIMEOUT)
|
||||||
|
|
||||||
# Response is a dictionary of information, 'None', or an erro
|
# Response is a dictionary of information, 'None', or an error string
|
||||||
data = request.content.decode('utf-8')
|
data = request.content.decode('utf-8')
|
||||||
|
|
||||||
# Server has nothing to run, ask again later
|
# Server has nothing to run, ask again later
|
||||||
@@ -428,10 +426,13 @@ if __name__ == '__main__':
|
|||||||
print ('<ERROR> Invalid Login Credentials')
|
print ('<ERROR> Invalid Login Credentials')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Server might reject our Machine ID
|
# Server might reject our Machine ID, in which case
|
||||||
|
# we register again, but without an ID number. Server
|
||||||
|
# will send us a new ID, and we can save that locally
|
||||||
if data == 'Bad Machine':
|
if data == 'Bad Machine':
|
||||||
print ('<ERROR> Bad Machine. Delete machine.txt')
|
print ('<ERROR> Bad Machine, Registering again')
|
||||||
sys.exit()
|
postdata['machineid'] = 'None'
|
||||||
|
continue
|
||||||
|
|
||||||
# Convert response into a data dictionary
|
# Convert response into a data dictionary
|
||||||
data = ast.literal_eval(data)
|
data = ast.literal_eval(data)
|
||||||
|
|||||||
Reference in new issue
Block a user