Skip to content

Commit

Permalink
fix(common): subgraph monitor query (#114)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Asseman <[email protected]>
  • Loading branch information
aasseman authored Feb 1, 2024
1 parent 6a0eed3 commit b55af5d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions common/src/subgraph_client/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
use std::time::Duration;

use eventuals::{timer, Eventual, EventualExt};
use graphql_http::http_client::{ReqwestExt, ResponseResult};
use graphql_http::{
http::request::IntoRequestParameters,
http_client::{ReqwestExt, ResponseResult},
};
use reqwest::Url;
use serde::Deserialize;
use serde_json::{json, Value};
use serde_json::json;
use thegraph::types::DeploymentId;
use tokio::time::sleep;
use tracing::warn;

use super::Query;

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct DeploymentStatusResponse {
Expand All @@ -26,14 +31,9 @@ pub struct DeploymentStatus {

async fn query<T: for<'de> Deserialize<'de>>(
url: Url,
body: &Value,
query: impl IntoRequestParameters + Send,
) -> Result<ResponseResult<T>, anyhow::Error> {
let serialized_body = serde_json::to_string(body)?;

Ok(reqwest::Client::new()
.post(url)
.send_graphql(serialized_body)
.await?)
Ok(reqwest::Client::new().post(url).send_graphql(query).await?)
}

pub fn monitor_deployment_status(
Expand All @@ -45,21 +45,19 @@ pub fn monitor_deployment_status(
let status_url = status_url.clone();

async move {
let body = json!({
"query": r#"
query indexingStatuses($ids: [ID!]!) {
let body = Query::new_with_variables(
r#"
query indexingStatuses($ids: [String!]!) {
indexingStatuses(subgraphs: $ids) {
synced
health
}
}
"#,
"variables": {
"ids": [deployment.to_string()]
}
});
[("ids", json!([deployment.to_string()]))],
);

let response = query::<DeploymentStatusResponse>(status_url, &body)
let response = query::<DeploymentStatusResponse>(status_url, body)
.await
.map_err(|e| {
format!("Failed to query status of deployment `{deployment}`: {e}")
Expand Down

0 comments on commit b55af5d

Please sign in to comment.