pub fn call(
        &self,
        env_path: Option<&str>,
        global_vars: &GlobalVars,
        runtime_vars: &RuntimeVars,
        handle: &mut CallbackHandle,
    ) -> AppResult<Option<ChildData>> {
        debug!(
            "ready to start callback {:?} with args={:?}, path={:?}, envs={:?}, current_dir={:?}",
            &self.callback,
            self.args,
            env_path,
            runtime_vars,
            std::env::current_dir()
                .map_err(|e| format!("unable to fetch current directory, error={}", e))
        );

        // the callback is called depending of its type
        match &self.callback {
            CallbackType::Script(path) => {
                // build Command struct before execution.
                debug_assert!(path.is_some());

                let mut cmd = Command::new(path.as_ref().unwrap());

                // user vars don't change so we can add them right now
                if global_vars.len() != 0 {
                    cmd.envs(global_vars);
                }

                // add arguments if any
                if let Some(args) = &self.args {
                    cmd.args(&args[..]);
                }

                //handle.cmd = Some(cmd);
                debug!("creating Command for: {:?}", path.as_ref().unwrap());

                // runtime variables are always there.
                for (var, value) in runtime_vars.inner() {
                    match var {
                        Cow::Borrowed(s) => cmd.env(s, value.to_string()),
                        Cow::Owned(s) => cmd.env(s, value.to_string()),
                    };
                }

                // update PATH variable if any
                if let Some(path) = env_path {
                    cmd.env("PATH", path);
                }

                // start command
                let child = cmd
                    .spawn()
                    .map_err(|e| context!(e, "unable to spawn process for cmd:{:?}", path))?;
                debug!("starting script {:?}, pid={}", path, child.id());

                Ok(Some(ChildData {
                    child: Some(RefCell::new(child)),
                    path: path.as_ref().unwrap().clone(),
                    timeout: self.timeout,
                    start_time: Some(Instant::now()),
                }))
            }
            CallbackType::Tcp(address) => {
                debug_assert!(address.is_some());
                let addr = address.as_ref().unwrap();

                // this is to control to send globals only once
                let mut first_time = false;

                // test whether a TCP socket is already created
                if handle.tcp_socket.is_none() {
                    let stream = TcpStream::connect(addr)
                        .map_err(|e| context!(e, "unable to connect to TCP address: {}", addr))?;

                    // set timeout for write operations
                    let write_timeout = Duration::new(self.timeout, 0);
                    stream
                        .set_write_timeout(Some(write_timeout))
                        .map_err(|e| context!(e, "unable to set socket timeout: {}", addr))?;

                    // save socket
                    handle.tcp_socket = Some(stream);
                    debug!("creating TCP socket for: {}", address.as_ref().unwrap());

                    first_time = true;
                }

                // send JSON data through TCP socket
                let stream = handle.tcp_socket.as_ref().unwrap();
                send_json_data(
                    &self.args,
                    stream,
                    global_vars,
                    runtime_vars,
                    first_time,
                    addr,
                )
            }
            #[cfg(target_family = "unix")]
            CallbackType::Domain(address) => {
                debug_assert!(address.is_some());
                let addr = address.as_ref().unwrap();

                // this is to control to send globals only once
                let mut first_time = false;

                // test whether a UNIX socket is already created
                if handle.domain_socket.is_none() {
                    let stream = UnixStream::connect(address.as_ref().unwrap()).map_err(|e| {
                        context!(e, "unable to connect to UNIX socket address: {:?}", addr)
                    })?;

                    // set timeout for write operations
                    let write_timeout = Duration::new(self.timeout, 0);
                    stream
                        .set_write_timeout(Some(write_timeout))
                        .map_err(|e| context!(e, "unable to set socket timeout: {:?}", addr))?;

                    handle.domain_socket = Some(stream);
                    debug!("creating UNIX socket for: {:?}", address.as_ref().unwrap());

                    first_time = true;
                }

                // send JSON data through UNIX socket
                let stream = handle.domain_socket.as_ref().unwrap();
                send_json_data(
                    &self.args,
                    stream,
                    global_vars,
                    runtime_vars,
                    first_time,
                    addr,
                )
            }
        }
    }
/// Calls the relevant callback with arguments
Calls the relevant callback with arguments
Calls the relevant callback with arguments
pub fn call(
        &self,
        env_path: Option<&str>,
        global_vars: &GlobalVars,
        runtime_vars: &RuntimeVars,
        handle: &mut CallbackHandle,
    ) -> AppResult<Option<ChildData>> {
        debug!(
            "ready to start callback {:?} with args={:?}, path={:?}, envs={:?}, current_dir={:?}",
            &self.callback,
            self.args,
            env_path,
            runtime_vars,
            std::env::current_dir()
                .map_err(|e| format!("unable to fetch current directory, error={}", e))
        );
        // the callback is called depending of its type
        match &self.callback {
            CallbackType::Script(path) => {
                // build Command struct before execution.
                debug_assert!(path.is_some());
                let mut cmd = Command::new(path.as_ref().unwrap());
                // user vars don't change so we can add them right now
                if global_vars.len() != 0 {
                    cmd.envs(global_vars);
                }
                // add arguments if any
                if let Some(args) = &self.args {
                    cmd.args(&args[..]);
                }
                //handle.cmd = Some(cmd);
                debug!("creating Command for: {:?}", path.as_ref().unwrap());
                // runtime variables are always there.
                for (var, value) in runtime_vars.inner() {
                    match var {
                        Cow::Borrowed(s) => cmd.env(s, value.to_string()),
                        Cow::Owned(s) => cmd.env(s, value.to_string()),
                    };
                }
                // update PATH variable if any
                if let Some(path) = env_path {
                    cmd.env("PATH", path);
                }
                // start command
                let child = cmd
                    .spawn()
                    .map_err(|e| context!(e, "unable to spawn process for cmd:{:?}", path))?;
                debug!("starting script {:?}, pid={}", path, child.id());
                Ok(Some(ChildData {
                    child: Some(RefCell::new(child)),
                    path: path.as_ref().unwrap().clone(),
                    timeout: self.timeout,
                    start_time: Some(Instant::now()),
                }))
            }
            CallbackType::Tcp(address) => {
                debug_assert!(address.is_some());
                let addr = address.as_ref().unwrap();
                // this is to control to send globals only once
                let mut first_time = false;
                // test whether a TCP socket is already created
                if handle.tcp_socket.is_none() {
                    let stream = TcpStream::connect(addr)
                        .map_err(|e| context!(e, "unable to connect to TCP address: {}", addr))?;
                    // set timeout for write operations
                    let write_timeout = Duration::new(self.timeout, 0);
                    stream
                        .set_write_timeout(Some(write_timeout))
                        .map_err(|e| context!(e, "unable to set socket timeout: {}", addr))?;
                    // save socket
                    handle.tcp_socket = Some(stream);
                    debug!("creating TCP socket for: {}", address.as_ref().unwrap());
                    first_time = true;
                }
                // send JSON data through TCP socket
                let stream = handle.tcp_socket.as_ref().unwrap();
                send_json_data(
                    &self.args,
                    stream,
                    global_vars,
                    runtime_vars,
                    first_time,
                    addr,
                )
            }
            #[cfg(target_family = "unix")]
            CallbackType::Domain(address) => {
                debug_assert!(address.is_some());
                let addr = address.as_ref().unwrap();
                // this is to control to send globals only once
                let mut first_time = false;
                // test whether a UNIX socket is already created
                if handle.domain_socket.is_none() {
                    let stream = UnixStream::connect(address.as_ref().unwrap()).map_err(|e| {
                        context!(e, "unable to connect to UNIX socket address: {:?}", addr)
                    })?;
                    // set timeout for write operations
                    let write_timeout = Duration::new(self.timeout, 0);
                    stream
                        .set_write_timeout(Some(write_timeout))
                        .map_err(|e| context!(e, "unable to set socket timeout: {:?}", addr))?;
                    handle.domain_socket = Some(stream);
                    debug!("creating UNIX socket for: {:?}", address.as_ref().unwrap());
                    first_time = true;
                }
                // send JSON data through UNIX socket
                let stream = handle.domain_socket.as_ref().unwrap();
                send_json_data(
                    &self.args,
                    stream,
                    global_vars,
                    runtime_vars,
                    first_time,
                    addr,
                )
            }
        }
    }
pub fn call ( & self , env_path : Option < & str > , global_vars : & GlobalVars , runtime_vars : & RuntimeVars , handle : & mut CallbackHandle , ) -> AppResult < Option < ChildData > > { debug ! ( " " self callback self args env_path runtime_vars std env current_dir ( ) map_err ( e format ( " " e ) ) ) ; // the callback is called depending of its type match & self . callback { CallbackType :: Script ( path ) => { // build Command struct before execution. debug_assert ! ( path is_some ( ) ) ; let mut cmd = Command :: new ( path . as_ref ( ) . unwrap ( ) ) ; // user vars don't change so we can add them right now if global_vars . len ( ) != 0 { cmd . envs ( global_vars ) ; } // add arguments if any if let Some ( args ) = & self . args { cmd . args ( & args [ .. ] ) ; } //handle.cmd = Some(cmd); debug ! ( " " path as_ref ( ) unwrap ( ) ) ; // runtime variables are always there. for ( var , value ) in runtime_vars . inner ( ) { match var { Cow :: Borrowed ( s ) => cmd . env ( s , value . to_string ( ) ) , Cow :: Owned ( s ) => cmd . env ( s , value . to_string ( ) ) , } ; } // update PATH variable if any if let Some ( path ) = env_path { cmd . env ( " " , path ) ; } // start command let child = cmd . spawn ( ) . map_err ( | e | context ! ( e " " path ) ) ? ; debug ! ( " " path child id ( ) ) ; Ok ( Some ( ChildData { child : Some ( RefCell :: new ( child ) ) , path : path . as_ref ( ) . unwrap ( ) . clone ( ) , timeout : self . timeout , start_time : Some ( Instant :: now ( ) ) , } ) ) } CallbackType :: Tcp ( address ) => { debug_assert ! ( address is_some ( ) ) ; let addr = address . as_ref ( ) . unwrap ( ) ; // this is to control to send globals only once let mut first_time = false ; // test whether a TCP socket is already created if handle . tcp_socket . is_none ( ) { let stream = TcpStream :: connect ( addr ) . map_err ( | e | context ! ( e " " addr ) ) ? ; // set timeout for write operations let write_timeout = Duration :: new ( self . timeout , 0 ) ; stream . set_write_timeout ( Some ( write_timeout ) ) . map_err ( | e | context ! ( e " " addr ) ) ? ; // save socket handle . tcp_socket = Some ( stream ) ; debug ! ( " " address as_ref ( ) unwrap ( ) ) ; first_time = true ; } // send JSON data through TCP socket let stream = handle . tcp_socket . as_ref ( ) . unwrap ( ) ; send_json_data ( & self . args , stream , global_vars , runtime_vars , first_time , addr , ) } # [ cfg ( target_family " " ) ] CallbackType :: Domain ( address ) => { debug_assert ! ( address is_some ( ) ) ; let addr = address . as_ref ( ) . unwrap ( ) ; // this is to control to send globals only once let mut first_time = false ; // test whether a UNIX socket is already created if handle . domain_socket . is_none ( ) { let stream = UnixStream :: connect ( address . as_ref ( ) . unwrap ( ) ) . map_err ( | e | { context ! ( e " " addr ) } ) ? ; // set timeout for write operations let write_timeout = Duration :: new ( self . timeout , 0 ) ; stream . set_write_timeout ( Some ( write_timeout ) ) . map_err ( | e | context ! ( e " " addr ) ) ? ; handle . domain_socket = Some ( stream ) ; debug ! ( " " address as_ref ( ) unwrap ( ) ) ; first_time = true ; } // send JSON data through UNIX socket let stream = handle . domain_socket . as_ref ( ) . unwrap ( ) ; send_json_data ( & self . args , stream , global_vars , runtime_vars , first_time , addr , ) } } }
Calls the relevant callback with arguments
Calls the relevant callback with arguments
&self
env_path
Option<&str>
global_vars
&GlobalVars
runtime_vars
&RuntimeVars
handle
&mut CallbackHandle
&self
env_path
Option<&str>
global_vars
&GlobalVars
runtime_vars
&RuntimeVars
handle
&mut CallbackHandle