示例#1
0
文件: job.py 项目: jjcorreao/tako
    def execute_executable(cls, name, task, input_values, execution_data):
        """ Executes the Task as an executable for the given input values on the local machine

        :param task: the task to execute
        :type task: tigres.type.Task
        :param input_values: the input values for the task
        :type input_values: InputValues or list

        """
        if not execution_data or 'job_id' not in list(execution_data.keys()):
            cmd = create_executable_command(input_values, task)

            # Build the Batch Job script
            job_script_name = cls.write_job_script(cmd, name)

            # Submit the batch job
            job_id = cls._submit_job(job_script_name, *execution_data['env'])
            execution_data['job_script_name'] = job_script_name
            execution_data['job_id'] = job_id

        # Determine if the job finishes
        if cls._is_job_finished(execution_data['job_id'],
                                execution_data['job_script_name']):
            error, output = cls._get_job_output(execution_data['job_id'],
                                                execution_data[
                                                    'job_script_name'])
            cls._clean_up_files(execution_data['job_script_name'])
            if not output and error:
                raise TigresException(error)

            return output, State.DONE
        else:
            return None, State.RUN
示例#2
0
文件: local.py 项目: jjcorreao/tako
    def execute_executable(cls, name, task, input_values, execution_data):
        """ Executes the Task as an executable for the given input values on the local machine

        :param task: the task to execute
        :type task: tigres.type.Task
        :param input_values: the input values for the task
        :type input_values: InputValues or list


        :Example:

        >>> from tigres.utils import Execution
        >>> from tigres.core.execution import load_plugin
        >>> engine = load_plugin(Execution.LOCAL_THREAD)
        >>> from tigres import InputTypes, InputValues, Task, EXECUTABLE
        >>> input_type_1 = InputTypes(None, [str])
        >>> task1 = Task(None, EXECUTABLE, "/bin/echo", input_type_1)
        >>> input_values_1 = InputValues(None, ['world'])
        >>> engine.execute_executable("foo bar", task1, input_values_1,{'env':{}})
        ('world', 'DONE')

        .. note::
            The current implementation will coerce all arguments to strings when it builds the
            command for command line execution
        """
        output = None

        if not execution_data or State.DONE not in list(execution_data.keys()):
            cmd = create_executable_command(input_values, task)
            # Get the current environment and pass it along to the executable
            copy_os_env = copy(os.environ)
            try:
                copy_os_env.update(execution_data['env'])
                output = run_command(cmd, env=copy_os_env)
                if execution_data is not None:
                    execution_data[State.DONE] = State.DONE
            except Exception as err:
                raise TigresException(
                    "Exception caught for execution '{w}', Task '{t}'. Error: {e}".format(
                        w=name, t=task.name, e=err))

        return output, State.DONE