Skip to content

Commit

Permalink
only post when state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaguilar committed Sep 15, 2023
1 parent 6f5f64b commit a0d7330
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl APIClient {
reqwest::header::HeaderValue::from_str(self.token.as_str()).unwrap(),
);
let mut waittime = 30;
let mut last_state = String::new();
loop {
let headers = token_header.clone();

Expand All @@ -86,15 +87,19 @@ impl APIClient {
serde_json::from_str(&body).expect("response body in wrong format");

if response.is_status_ok() {
let headers = token_header.clone();
let mut map = HashMap::new();
map.insert("status", response.data[0].current_state.as_str());
client
.post(url.as_str())
.headers(headers)
.json(&map)
.send()
.await?;
let current_state = response.data[0].current_state.clone();
if last_state != current_state {
let headers = token_header.clone();
let mut map = HashMap::new();
map.insert("status", response.data[0].current_state.as_str());
client
.post(url.as_str())
.headers(headers)
.json(&map)
.send()
.await?;
last_state = current_state;
}

if !response.is_complete() {
println!("workflow is still running");
Expand Down

0 comments on commit a0d7330

Please sign in to comment.