Esempio n. 1
0
def main(args):
    _set_logging()
    logging.info("Starting up worker at {}".format(socket.gethostname()))
    threading.Thread(target=app.run,
                     kwargs={
                         'host': '0.0.0.0',
                         'port': 5001,
                         'threaded': True
                     }).start()
    while True:
        set_time()
        try:
            logging.debug("\n\n\nQuerying for new task at time %s (GMT)\n" %
                          str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))

            task = backend.getTask(args.task_type)
            if "type" in task and (task["type"] == "compile"
                                   or task["type"] == "game"):
                logging.debug("Got new task at time %s (GMT)\n" %
                              str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
                logging.debug("Task object %s\n" % str(task))

                if task["type"] == "compile":
                    logging.debug("Running a compilation task...\n")
                    executeCompileTask(task["user"], task["bot"], backend)
                else:
                    logging.debug("Running a game task...\n")
                    executeGameTask(task.get("environment_parameters", {}),
                                    task["users"], {
                                        "challenge": task.get("challenge"),
                                    }, backend.gameResult)
            elif task.get("type") == "ondemand":
                environment_params = task["environment_parameters"]
                extra_metadata = {
                    "task_user_id": task["task_user_id"],
                    "offset": int(args.user_offset),
                }

                try:
                    executeGameTask(environment_params, task["users"],
                                    extra_metadata, backend.ondemandResult)
                except OndemandCompileError as e:
                    backend.ondemandError(task["users"], extra_metadata,
                                          e.language, e.log)
            else:
                logging.debug(
                    "No task available at time %s (GMT). Sleeping...\n" %
                    str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
                sleep(random.randint(1, 4))
        except Exception as e:
            logging.exception("Error on get task %s\n" % str(e))

            logging.debug("Sleeping...\n")
            sleep(random.randint(1, 4))
Esempio n. 2
0
def main():
    _set_logging()
    logging.info("Starting up worker at {}".format(socket.gethostname()))
    threading.Thread(target=app.run,
                     kwargs={
                         'host': '0.0.0.0',
                         'port': 5001,
                         'threaded': True
                     }).start()
    while True:
        set_time()
        try:
            logging.debug("\n\n\nQuerying for new task at time %s (GMT)\n" %
                          str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
            task = backend.getTask()
            if "type" in task and (task["type"] == "compile"
                                   or task["type"] == "game"):
                logging.debug("Got new task at time %s (GMT)\n" %
                              str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
                logging.debug("Task object %s\n" % str(task))
                if task["type"] == "compile":
                    logging.debug("Running a compilation task...\n")
                    executeCompileTask(task["user"], task["bot"], backend)
                else:
                    logging.debug("Running a game task...\n")
                    executeGameTask(int(task["width"]), int(task["height"]),
                                    task["users"], backend)
            else:
                logging.debug(
                    "No task available at time %s (GMT). Sleeping...\n" %
                    str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
        except Exception as e:
            logging.exception("Error on get task %s\n" % str(e))

        logging.debug("Sleeping...\n")
        sleep(random.randint(4, 10))
Esempio n. 3
0
    fOut.close()

    backend.gameResult(width, height, users, replayArchivePath, errorPaths)
    filelist = glob.glob("*.log")
    for f in filelist:
        os.remove(f)

    os.remove(replayPath)
    os.remove(replayArchivePath)

if __name__ == "__main__":
    print("\n\n\n\nStarting up worker...\n\n\n")
    while True:
        try:
            print("\n\n\nQuerying for new task at time %s (GMT)\n" % str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
            task = backend.getTask()
            if "type" in task and (task["type"] == "compile" or task["type"] == "game"):
                print("Got new task at time %s (GMT)\n" % str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
                print("Task object %s\n" % str(task))
                if task["type"] == "compile":
                    print("Running a compilation task...\n")
                    executeCompileTask(task["user"], backend)
                else:
                    print("Running a game task...\n")
                    executeGameTask(int(task["width"]), int(task["height"]), task["users"], backend)
            else:
                print("No task available at time %s (GMT). Sleeping...\n" % str(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
                sleep(2)
        except Exception as e:
            print("Error on get task %s\n" % str(e))
            print("Sleeping...\n")
Esempio n. 4
0
    fOut.close()

    backend.gameResult(width, height, users, replayArchivePath, errorPaths)
    filelist = glob.glob("*.log")
    for f in filelist:
        os.remove(f)

    os.remove(replayPath)
    os.remove(replayArchivePath)


if __name__ == "__main__":
    print("Starting up worker...")
    while True:
        try:
            task = backend.getTask()
            if "type" in task and (task["type"] == "compile"
                                   or task["type"] == "game"):
                print("Got new task: " + str(task))
                if task["type"] == "compile":
                    executeCompileTask(task["user"], backend)
                else:
                    executeGameTask(int(task["width"]), int(task["height"]),
                                    task["users"], backend)
            else:
                print("No task available. Sleeping...")
                sleep(2)
        except Exception as e:
            print("Error on get task:")
            print(e)
            print("Sleeping...")