Beispiel #1
0
    def run(
        self,
        cmdline,
        out_path=None,
        err_path=None,
        input_str=None,
        directory=None,
        **kwargs,
    ):
        out_file = open(out_path, "wb")
        err_file = open(err_path, "wb")

        monitor = ProcessMonitor(
            cmdline,
            cwd=directory,
            stdout=out_file,
            stderr=err_file,
            input=input_str,
            freq=15,
        )
        monitor.subscribe("wall_time", WallTimeLimiter(self.wall_limit))
        monitor.subscribe("cpu_time", CpuTimeLimiter(self.cpu_limit))
        monitor.subscribe("max_memory", MaxMemoryLimiter(self.mem_limit))

        logger.debug(f"Running {directory}")
        stats = monitor.run()
        logger.debug(f"Finished {directory}")

        out_file.close()
        err_file.close()

        payload = self.compile_stats(stats)
        send_event(self.socket, STORE_RUNSTATS, payload)
Beispiel #2
0
    def run(self):
        atexit.register(self.killed, self.run_id)

        context = zmq.Context()
        self.socket = context.socket(zmq.DEALER)
        self.socket.connect(self.server_address)

        send_event(self.socket, WORKER_JOIN, self.run_id)
        run = decode_message(self.socket.recv())

        tool = import_class(run["tool"])

        context = {}
        context["socket"] = self.socket
        context["tool"] = tool
        context["run"] = run
        logger.info(f"Processing task: {run['directory']}")

        directory = Path(run["directory"])
        directory.mkdir(parents=True, exist_ok=True)

        payload = dict(tool_version=tool.version(), run_id=self.run_id)
        send_event(self.socket, RUN_START, payload)

        for runstep in run["steps"]:
            logger.debug(f"Running step {runstep['module']}")
            step = import_class(runstep["module"])
            config = json.loads(runstep["config"])
            step.execute(context, config)
            payload = {"run_id": self.run_id, "step": runstep["module"]}
            send_event(self.socket, RUN_STEP, payload)

        send_event(self.socket, RUN_FINISH, self.run_id)
        atexit.unregister(self.killed)
        send_event(self.socket, WORKER_LEAVE, self.run_id)
Beispiel #3
0
    def execute(cls, context, config=None):
        tool = context["tool"](context)
        task = Path(tool.task).read_text()
        output = tool.get_output().decode()

        satisfiable = "c NOTE: Satisfiable".lower() in task.lower()

        is_valid = (satisfiable and "s SATISFIABLE" in output) or (
            not satisfiable and "s UNSATISFIABLE" in output
        )

        payload = dict(run=context["run"]["id"], is_valid=is_valid)
        send_event(context["socket"], STORE_SAT_VERDICT, payload)
Beispiel #4
0
    def bootstrap(self):
        self.socket.connect(self.server_address)

        client_results = bootstrap_client(self.config)
        bootstrapped_config = {**self.config, **client_results}

        logger.info("Sending bootstrap event to server")
        payload = dict(config=bootstrapped_config,
                       output_dir=self.output_dir,
                       repeat=self.repeat)
        send_event(self.socket, BOOTSTRAP, payload)

        self.pending = decode_message(self.socket.recv())
Beispiel #5
0
def cli(server_address, config, output_dir, **kwargs):
    config = read_config(config, resolve_files=True)

    client_results = bootstrap_client(config)
    bootstrapped_config = {**config, **client_results}

    context = zmq.Context()
    socket = context.socket(zmq.DEALER)
    socket.connect(server_address)
    payload = dict(config=bootstrapped_config, output_dir=output_dir, **kwargs)

    logger.info("Sending bootstrap event to server")
    send_event(socket, BOOTSTRAP, payload)
Beispiel #6
0
    def execute(cls, context, config=None):
        tool = context["tool"](context)
        task = cls._filter_empty_lines(Path(tool.task).read_text().split("\n"))
        output = cls._filter_empty_lines(
            tool.get_output().decode().split("\n"))

        is_valid = True

        if len(output) < len(task):
            is_valid = False

        if is_valid and config.get("check_consistency", False):
            is_valid = cls._check_consistency(task, output)

        if is_valid:
            parsed = cls._parse_sudoku(output)
            is_valid = cls._check_sudoku_constraints(parsed)

        payload = dict(run=context["run"]["id"], is_valid=is_valid)
        send_event(context["socket"], STORE_SUDOKU_VERDICT, payload)
Beispiel #7
0
 def get_pending_runs(self):
     send_event(self.socket, REQUEST_PENDING)
     self.queue = decode_message(self.socket.recv())
Beispiel #8
0
 def execute(cls, context, config=None):
     hostname = platform.node()
     info = cls._get_system_info()
     run_id = context["run"]["id"]
     payload = dict(run_id=run_id, node=dict(hostname=hostname, **info))
     send_event(context["socket"], STORE_SYSINFO, payload)
Beispiel #9
0
 def killed(self, run_id):
     send_event(self.socket, RUN_INTERRUPT, run_id)
     send_event(self.socket, WORKER_LEAVE)