|
1 | 1 | // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -use std::time::Duration; |
5 | 4 | use reqwest::Url; |
6 | 5 | use serde::Deserialize; |
7 | 6 | use serde_json::json; |
| 7 | +use std::time::Duration; |
8 | 8 | use thegraph_core::DeploymentId; |
9 | 9 | use thegraph_graphql_http::{ |
10 | 10 | http::request::IntoRequestParameters, |
11 | 11 | http_client::{ReqwestExt, ResponseResult}, |
12 | 12 | }; |
13 | | -use tokio::{sync::watch::{self, Receiver}, time::{self, sleep}}; |
| 13 | +use tokio::{ |
| 14 | + sync::watch::{self, Receiver}, |
| 15 | + time::{self, sleep}, |
| 16 | +}; |
14 | 17 | use tracing::warn; |
15 | 18 |
|
16 | 19 | use super::Query; |
@@ -57,29 +60,26 @@ pub fn monitor_deployment_status( |
57 | 60 | [("ids", json!([deployment.to_string()]))], |
58 | 61 | ); |
59 | 62 | let response = query::<DeploymentStatusResponse>(status_url, body) |
60 | | - .await |
61 | | - .map_err(|e| { |
62 | | - format!("Failed to query status of deployment `{deployment}`: {e}") |
63 | | - }).unwrap(); |
| 63 | + .await |
| 64 | + .map_err(|e| format!("Failed to query status of deployment `{deployment}`: {e}")) |
| 65 | + .unwrap(); |
64 | 66 | let result = response.map_err(|e| format!("{e}")).and_then(|data| { |
65 | 67 | data.indexing_statuses |
66 | 68 | .and_then(|statuses| statuses.first().cloned()) |
67 | 69 | .ok_or_else(|| format!("Deployment `{deployment}` not found")) |
68 | 70 | }); |
69 | | - match result{ |
| 71 | + match result { |
70 | 72 | Ok(deployment_status) => { |
71 | | - dbg!("Sending......"); |
72 | | - tx |
73 | | - .send(Some(deployment_status)) |
74 | | - .expect("Failed to update deployment_status channel"); |
75 | | - }, |
76 | | - Err(err) =>{ |
| 73 | + tx.send(Some(deployment_status)) |
| 74 | + .expect("Failed to update deployment_status channel"); |
| 75 | + } |
| 76 | + Err(err) => { |
77 | 77 | warn!( |
78 | 78 | "Error querying deployment status for `{}`: {}", |
79 | 79 | deployment, err |
80 | 80 | ); |
81 | 81 | sleep(Duration::from_secs(15)).await; |
82 | | - }, |
| 82 | + } |
83 | 83 | } |
84 | 84 | } |
85 | 85 | }); |
@@ -122,15 +122,15 @@ mod tests { |
122 | 122 | .mount(&mock_server) |
123 | 123 | .await; |
124 | 124 |
|
125 | | - let mut status_rx = monitor_deployment_status(deployment, status_url); |
126 | | - status_rx.changed().await.unwrap(); |
127 | | - let status_ref = status_rx.borrow(); |
128 | | - assert_eq!( |
129 | | - status_ref.as_ref().unwrap().clone(), |
130 | | - DeploymentStatus { |
131 | | - synced: true, |
132 | | - health: "healthy".to_string() |
133 | | - } |
| 125 | + let mut status_rx = monitor_deployment_status(deployment, status_url); |
| 126 | + status_rx.changed().await.unwrap(); |
| 127 | + let status_ref = status_rx.borrow(); |
| 128 | + assert_eq!( |
| 129 | + status_ref.as_ref().unwrap().clone(), |
| 130 | + DeploymentStatus { |
| 131 | + synced: true, |
| 132 | + health: "healthy".to_string() |
| 133 | + } |
134 | 134 | ); |
135 | 135 | } |
136 | 136 |
|
@@ -161,15 +161,15 @@ mod tests { |
161 | 161 | .mount(&mock_server) |
162 | 162 | .await; |
163 | 163 |
|
164 | | - let mut status_rx = monitor_deployment_status(deployment, status_url); |
165 | | - status_rx.changed().await.unwrap(); |
166 | | - let status_ref = status_rx.borrow(); |
167 | | - assert_eq!( |
168 | | - status_ref.as_ref().unwrap().clone(), |
169 | | - DeploymentStatus { |
170 | | - synced: false, |
171 | | - health: "healthy".to_string() |
172 | | - } |
| 164 | + let mut status_rx = monitor_deployment_status(deployment, status_url); |
| 165 | + status_rx.changed().await.unwrap(); |
| 166 | + let status_ref = status_rx.borrow(); |
| 167 | + assert_eq!( |
| 168 | + status_ref.as_ref().unwrap().clone(), |
| 169 | + DeploymentStatus { |
| 170 | + synced: false, |
| 171 | + health: "healthy".to_string() |
| 172 | + } |
173 | 173 | ); |
174 | 174 | } |
175 | 175 |
|
@@ -200,15 +200,15 @@ mod tests { |
200 | 200 | .mount(&mock_server) |
201 | 201 | .await; |
202 | 202 |
|
203 | | - let mut status_rx = monitor_deployment_status(deployment, status_url); |
204 | | - status_rx.changed().await.unwrap(); |
205 | | - let status_ref = status_rx.borrow(); |
206 | | - assert_eq!( |
207 | | - status_ref.as_ref().unwrap().clone(), |
208 | | - DeploymentStatus { |
209 | | - synced: true, |
210 | | - health: "unhealthy".to_string() |
211 | | - } |
| 203 | + let mut status_rx = monitor_deployment_status(deployment, status_url); |
| 204 | + status_rx.changed().await.unwrap(); |
| 205 | + let status_ref = status_rx.borrow(); |
| 206 | + assert_eq!( |
| 207 | + status_ref.as_ref().unwrap().clone(), |
| 208 | + DeploymentStatus { |
| 209 | + synced: true, |
| 210 | + health: "unhealthy".to_string() |
| 211 | + } |
212 | 212 | ); |
213 | 213 | } |
214 | 214 |
|
|
0 commit comments