Ejemplo n.º 1
0
    def invoke(self):
        def timeout_handle(child):
            click.secho('Function Timeout.', fg="red")
            child.kill()
            self._thread_err_msg = 'Function "%s" timeout after %d seconds' % (self._function, self._runtime.timeout)

        try:
            click.secho("Run %s's cmd: %s" % (self._runtime.runtime, click.style(self.cmd, fg="green")))
            child = subprocess.Popen(args=[self.cmd] + self.argv, env=self.env)
        except OSError:
            click.secho("Execution Failed.", fg="red")
            raise UserException(
                "Execution failed,confirm whether the program({}) is installed".format(self._runtime.cmd))

        timer = threading.Timer(self._runtime.timeout, timeout_handle, [child])

        if not self._debug_context.is_debug:
            timer.start()
        else:
            click.secho("Scf debug port is listening on localhost:{}".format(str(self._debug_port)), fg="green")
        ret_code = 0
        try:
            ret_code = child.wait()
        except KeyboardInterrupt:
            child.kill()
            click.secho("Recv a SIGINT, exit.")
        timer.cancel()
        if self._thread_err_msg != "":
            raise TimeoutException(self._thread_err_msg)
        if ret_code == 233:  # runtime not match
            raise UserException(
                "Execution failed,confirm whether the program({}) is installed".format(self._runtime.runtime))
Ejemplo n.º 2
0
def do_invoke(template, namespace_identifier, function_identifier, event,
              no_event, env_vars, debug_port, debug_args, debugger_path,
              docker_volume_basedir, docker_network, log_file, skip_pull_image,
              region):

    if no_event and event != STD_IN:
        raise UserException(
            'event is conflict with no_event, provide only one.')

    if no_event:
        event_data = '{}'
    else:
        event_data = _get_event(event)

    try:
        with InvokeContext(template_file=template,
                           function_identifier=function_identifier,
                           env_vars_file=env_vars,
                           debug_port=debug_port,
                           debug_args=debug_args,
                           debugger_path=debugger_path,
                           docker_volume_basedir=docker_volume_basedir,
                           docker_network=docker_network,
                           log_file=log_file,
                           skip_pull_image=skip_pull_image,
                           region=region,
                           namespace=namespace_identifier) as context:

            context.local_runtime_manager.invoke(context.functions_name,
                                                 event_data, context.stdout,
                                                 context.stderr)

    except Exception as e:
        raise e
Ejemplo n.º 3
0
    def start(self):
        try:
            child = subprocess.Popen(args=[self.cmd] + self.argv, env=self.env)
        except OSError:
            click.secho("Execution Failed.", fg="red")
            raise UserException(
                "Execution failed,confirm whether the program({}) is installed"
                .format(self._runtime.cmd))

        ret_code = 0
        try:
            ret_code = child.wait()
        except KeyboardInterrupt:
            child.kill()
            click.secho("Recv a SIGINT, exit.")

        if ret_code == 233:  # runtime not match
            raise UserException(
                "Execution failed,confirm whether the program({}) is installed"
                .format(self._runtime.runtime))