コード例 #1
0
    def run_job(self, args):
        assert isinstance(args["jobID"], int)
        assert isinstance(args["title"], (str, unicode))
        assert isinstance(args["imageURL"], (str, unicode))
        assert isinstance(args["url"], (str, unicode))
        assert isinstance(args["outputDir"], (str, unicode))
        job_ID, title, image_URL = args["jobID"], args["title"], args["imageURL"]

        exec_args = ["/usr/bin/env", "python", CONVERTER_RUN_SCRIPT_PATH,
                     args["url"], args["outputDir"], str(args["jobID"]), "--web-mode"]
        process = subprocess.Popen(exec_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        yield self.send_job_started_notification(job_ID, title, image_URL)

        start_progr_indicator = helpers.ProgressBar.START_PROGRESS_INDICATOR
        end_progr_indicator = helpers.ProgressBar.END_PROGRESS_INDICATOR
        line_buffer = []
        old_progress = 0
        while True:
            line = process.stdout.readline()
            if line == '': break
            line = line.rstrip()

            # case: progress update
            if line.startswith(start_progr_indicator) and line.endswith(end_progr_indicator):
                progress = line.split(start_progr_indicator)[1].split(end_progr_indicator)[0]
                if not helpers.isfloat(progress):
                    _logger.warn("[%s]: Ignoring line! Parsed progress is no valid float: '%s'"
                                 % (CLIENT, progress))
                    continue

                progress = int(float(progress))
                progress_difference = progress - old_progress
                old_progress = progress
                if progress_difference > 0:
                    _logger.debug("[{}]: {}".format(CLIENT, progress))
                    yield self.send_job_progress_notification(job_ID, progress)
                continue

            # case: console output
            _logger.debug("[%s]: %s" % (CLIENT, line))
            line_buffer += [line]
            if self._verbose and len(line_buffer) >= LINE_BUFFER_SIZE:
                yield self.send_job_output_notification(job_ID, line_buffer)
                line_buffer = []

        if self._verbose and len(line_buffer):
            yield self.send_job_output_notification(job_ID, line_buffer)

        exit_code = process.wait() # XXX: work around this when experiencing errors...
        _logger.info("[%s]: Exit code is: %d" % (CLIENT, exit_code))

        # NOTE: exit-code is evaluated by TCP server
        yield self.send_job_conversion_finished_notification(job_ID, exit_code)
コード例 #2
0
    def run_job(self, args):
        assert isinstance(args["jobID"], int)
        assert isinstance(args["title"], (str, unicode))
        assert isinstance(args["imageURL"], (str, unicode))
        assert isinstance(args["url"], (str, unicode))
        assert isinstance(args["outputDir"], (str, unicode))
        job_ID, title, image_URL = args["jobID"], args["title"], args[
            "imageURL"]

        exec_args = [
            "/usr/bin/env", "python", CONVERTER_RUN_SCRIPT_PATH, args["url"],
            args["outputDir"],
            str(args["jobID"]), "--web-mode"
        ]
        process = subprocess.Popen(exec_args,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT)
        yield self.send_job_started_notification(job_ID, title, image_URL)

        start_progr_indicator = helpers.ProgressBar.START_PROGRESS_INDICATOR
        end_progr_indicator = helpers.ProgressBar.END_PROGRESS_INDICATOR
        line_buffer = []
        old_progress = 0
        while True:
            line = process.stdout.readline()
            if line == '': break
            line = line.rstrip()

            # case: progress update
            if line.startswith(start_progr_indicator) and line.endswith(
                    end_progr_indicator):
                progress = line.split(start_progr_indicator)[1].split(
                    end_progr_indicator)[0]
                if not helpers.isfloat(progress):
                    _logger.warn(
                        "[%s]: Ignoring line! Parsed progress is no valid float: '%s'"
                        % (CLIENT, progress))
                    continue

                progress = int(float(progress))
                progress_difference = progress - old_progress
                old_progress = progress
                if progress_difference > 0:
                    _logger.debug("[{}]: {}".format(CLIENT, progress))
                    yield self.send_job_progress_notification(job_ID, progress)
                continue

            # case: console output
            _logger.debug("[%s]: %s" % (CLIENT, line))
            line_buffer += [line]
            if self._verbose and len(line_buffer) >= LINE_BUFFER_SIZE:
                yield self.send_job_output_notification(job_ID, line_buffer)
                line_buffer = []

        if self._verbose and len(line_buffer):
            yield self.send_job_output_notification(job_ID, line_buffer)

        exit_code = process.wait(
        )  # XXX: work around this when experiencing errors...
        _logger.info("[%s]: Exit code is: %d" % (CLIENT, exit_code))

        # NOTE: exit-code is evaluated by TCP server
        yield self.send_job_conversion_finished_notification(job_ID, exit_code)