コード例 #1
0
    def process_job(self, options, config, store_result=True):
        """ Runs a given job configuration """

        def get_result_filename():
            """ Returns the result filename """
            return os.path.abspath(self.directory.join("results", self.directory.config_filename(config)))

        if store_result and not self.directory:
            raise Exception("Cannot store result without directory")

        logger.info("Run %s", job_runner_util.pretty_dict(config))

        if store_result:
            # Check if result file is already existing, return old result in this case
            # Do not re-run a configuration
            if os.path.exists(get_result_filename()):
                return json.loads(open(get_result_filename()).read())

        result = self.call_handler(config)
        if result:
            # A return value indicates a successful run
            logger.info("Run %s finished: %s", config, result)
            result["config"] = config

            if store_result:
                json.dump(result, open(get_result_filename(), "w"), sort_keys=True, indent=4)
        else:
            logger.warn("Execution error: %s", config)
        return result
コード例 #2
0
ファイル: job_runner.py プロジェクト: ramygad/fast_job_runner
    def process_job(self, options, config, store_result=True):
        """ Runs a given job configuration """

        def get_result_filename():
            """ Returns the result filename """
            return os.path.abspath(
                self.directory.join("results", 
                self.directory.config_filename(config)))

        if store_result and not self.directory:
            raise Exception("Cannot store result without directory")

        logger.info('Run %s', job_runner_util.pretty_dict(config))

        if store_result:
            # Check if result file is already existing, return old result in this case
            # Do not re-run a configuration
            if os.path.exists(get_result_filename()):
                return json.loads(open(get_result_filename()).read())

        result= self.call_handler(config)
        if result:
            # A return value indicates a successful run
            logger.info("Run %s finished: %s", config, result)
            result["config"] = config
                
            if store_result:
                json.dump(result, open(get_result_filename(), "w"), 
                    sort_keys=True, 
                    indent=4)
        else:
            logger.warn("Execution error: %s", config)
        return result
コード例 #3
0
ファイル: job_runner.py プロジェクト: ramygad/fast_job_runner
def main(handler, prefix = None, configuration_space = None, parser = None, install_signal=True):
    if install_signal:
        # Allows to act on a SIGTERM signal to move the current configuration file
        # away from the wip directory
        def sys_exit_handler(signum, frame):
            sys.exit(1)
        signal.signal(signal.SIGTERM, sys_exit_handler)

    (jr, argv) = create_job_runner(handler, prefix, parser)

    if configuration_space and jr.options.generate_configs:
        # Fix type
        if type(configuration_space) == dict:
            configuration_space = job_runner_configuration.ConfigurationSpace(configuration_space)
        configuration_space.generate_files(jr.directory)  
    elif len(argv) > 0:
        for arg in argv:
            o = jr.run_job(options, arg)
            logging.info(job_runner_util.pretty_dict(o))
    else:
        jr.start()
コード例 #4
0
def main(handler, prefix=None, configuration_space=None, parser=None, install_signal=True):
    if install_signal:
        # Allows to act on a SIGTERM signal to move the current configuration file
        # away from the wip directory
        def sys_exit_handler(signum, frame):
            sys.exit(1)

        signal.signal(signal.SIGTERM, sys_exit_handler)

    (jr, argv) = create_job_runner(handler, prefix, parser)

    if configuration_space and jr.options.generate_configs:
        # Fix type
        if type(configuration_space) == dict:
            configuration_space = job_runner_configuration.ConfigurationSpace(configuration_space)
        configuration_space.generate_files(jr.directory)
    elif len(argv) > 0:
        for arg in argv:
            o = jr.run_job(options, arg)
            logging.info(job_runner_util.pretty_dict(o))
    else:
        jr.start()