Skip to content

Commit

Permalink
remove request from queue only after success (status 200) from destin…
Browse files Browse the repository at this point in the history
…ation server
  • Loading branch information
konnek1ive committed Nov 30, 2023
1 parent 8175bab commit a50354d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ pub async fn main() {
body = out_bind.get("body");

// println!("{} - {} - {} - {}", method, host, uri, body);
send_stored_request(http_proto.clone(), http_dest.clone(), uri.clone(), body.clone(), &interval_pool).await;
delete_request_from_db(uri.clone(), body.clone(), &interval_pool).await;
let send_success = send_stored_request(http_proto.clone(), http_dest.clone(), uri.clone(), body.clone(), &interval_pool).await;
if send_success {
delete_request_from_db(uri.clone(), body.clone(), &interval_pool).await;
}
}

// let result: String = out.expect("cannot execute query").get("host");
Expand Down
13 changes: 11 additions & 2 deletions src/manage_requests/request_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ pub async fn delete_request_from_db(uri:String, body: String, pool: &Pool<MySql>
}


pub async fn send_stored_request(http_proto: String, http_dest: String, uri: String, body: String, pool: &Pool<MySql>) {
pub async fn send_stored_request(http_proto: String, http_dest: String, uri: String, body: String, pool: &Pool<MySql>) -> bool {
let built_uri = format!("{}://{}{}", http_proto, http_dest, uri);
println!("Sending Request;\n{}", built_uri);
println!("{}\n", body);
let _res = reqwest::Client::new()
let res = reqwest::Client::new()
.post(built_uri)
.body(body)
.send()
.await;

let mut success = false;
if res.is_ok() {
match res.unwrap().status().as_u16() {
(200) => success = true,
_ => success = false

}
}
success
}

0 comments on commit a50354d

Please sign in to comment.