fn run_json_sender_worker(config: Config, sync: Arc<(Mutex<Vec<Vec<u8>>>, Condvar)>, client: Arc<hyper::Client>) -> Result<(), Error> {
    let &(ref lock, ref cvar) = &*sync;
    loop {
        let mut items = lock.lock().expect("client failed to acquire lock");

        if items.len() == 0 {
            items = cvar.wait(items).expect("client failed to wait")
        }

        match items.pop() {
            Some(item) => {
                info!("SENDING: {} bytes", item.len());

                let mut headers = Headers::new();
                headers.set(ContentType(Mime(
                    TopLevel::Application,
                    SubLevel::Json,
                    vec![(Attr::Charset, Value::Utf8)],
                )));

                let res = client.post(config.receiver_url.as_str())
                    .headers(headers)
                    .body(item.as_slice())
                    .send();

                match res {
                    Ok(response) => {
                        info!("RESPONSE: {}", response.status);
                    },
                    Err(e) => {
                        info!("REQUEST_ERROR: {}", e.description());
                    },
                }
            },
            None => {
                debug!("client: nothing to do");
            }
        }
    }
}
/// Starts a worker that waits for JSON payloads to send
Starts a worker that waits for JSON payloads to send
Starts a worker that waits for JSON payloads to send
fn run_json_sender_worker(config: Config, sync: Arc<(Mutex<Vec<Vec<u8>>>, Condvar)>, client: Arc<hyper::Client>) -> Result<(), Error> {
    let &(ref lock, ref cvar) = &*sync;
    loop {
        let mut items = lock.lock().expect("client failed to acquire lock");
        if items.len() == 0 {
            items = cvar.wait(items).expect("client failed to wait")
        }
        match items.pop() {
            Some(item) => {
                info!("SENDING: {} bytes", item.len());
                let mut headers = Headers::new();
                headers.set(ContentType(Mime(
                    TopLevel::Application,
                    SubLevel::Json,
                    vec![(Attr::Charset, Value::Utf8)],
                )));
                let res = client.post(config.receiver_url.as_str())
                    .headers(headers)
                    .body(item.as_slice())
                    .send();
                match res {
                    Ok(response) => {
                        info!("RESPONSE: {}", response.status);
                    },
                    Err(e) => {
                        info!("REQUEST_ERROR: {}", e.description());
                    },
                }
            },
            None => {
                debug!("client: nothing to do");
            }
        }
    }
}
fn run_json_sender_worker ( config : Config , sync : Arc < ( Mutex < Vec < Vec < u8 > > > , Condvar ) > , client : Arc < hyper :: Client > ) -> Result < ( ) , Error > { let & ( ref lock , ref cvar ) = & * sync ; loop { let mut items = lock . lock ( ) . expect ( " " ) ; if items . len ( ) == 0 { items = cvar . wait ( items ) . expect ( " " ) } match items . pop ( ) { Some ( item ) => { info ! ( " " item len ( ) ) ; let mut headers = Headers :: new ( ) ; headers . set ( ContentType ( Mime ( TopLevel :: Application , SubLevel :: Json , vec ! [ ( Attr Charset Value Utf8 ) ] , ) ) ) ; let res = client . post ( config . receiver_url . as_str ( ) ) . headers ( headers ) . body ( item . as_slice ( ) ) . send ( ) ; match res { Ok ( response ) => { info ! ( " " response status ) ; } , Err ( e ) => { info ! ( " " e description ( ) ) ; } , } } , None => { debug ! ( " " ) ; } } } }
Starts a worker that waits for JSON payloads to send
Starts a worker that waits for JSON payloads to send
config
Config
sync
Arc<(Mutex<Vec<Vec<u8>>>, Condvar)>
client
Arc<hyper::Client>
config
Config
sync
Arc<(Mutex<Vec<Vec<u8>>>, Condvar)>
client
Arc<hyper::Client>