def runExperiment(interval, url, logfile): import json from datetime import datetime from time import sleep descriptions = {} descriptions["errors"] = [] while True: startTime = datetime.now() print("TICK! Checking potatoes...") token = postImage(url) attempt = 0 description = None print("Fetching description. {} attempts in {}s intervals.".format(MAX_ATTEMPTS, TIMEOUT_FETCH)) while not description and attempt < MAX_ATTEMPTS: sleep(TIMEOUT_FETCH) print("{} attempt to fetch result...".format(attempt)) attempt += 1 description = getDescription(token) when = str(datetime.now()) print("{} @ {}".format(description, when)) print( " * Veryfing that data assigned to returned token is immutable in {}s intervals...".format(TIMEOUT_VERIFY) ) desc_unique = set([description]) for i in range(4): sleep(TIMEOUT_VERIFY) print("{} fetch.".format(i)) descu = getDescription(token) desc_unique.add(descu) if len(desc_unique) > 1: print("!! Got different descriptions out of one token: {}".format(desc_unique)) descriptions["errors"].append((description, str(desc_unique))) if description in descriptions: descriptions[description].append(when) else: descriptions[description] = [when] with open(logfile, "w+") as fh: print("Updating file...") fh.write(json.dumps(descriptions)) print("Sleeping... zzz.... hrrrr.... zzzz....") delta = (datetime.now() - startTime).seconds snooze = interval - delta if snooze > 0: print("Work took {}s. Sleeping for {}s... (interval is {}s)".format(delta, snooze, interval)) sleep(snooze)
def runExperiment(url): import json from datetime import datetime from time import sleep descriptions = {} descriptions['errors'] = [] print ("Submitting request for {}...".format(url)) token = postImage(url) print ("Starting fetching results from the image (the total request remaining should be 1 less and not the number of pulls set to {}...".format(PULLS)) for i in range(PULLS): print ("Fetch: {}.".format(i)) description = getDescription(token) print ("Recieved description: {}".format(description)) print ("Finished the experiment.")