Skip to content

Commit

Permalink
feat: query grpc status server
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Dec 21, 2023
1 parent d6165e1 commit 7fcb8fa
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 4 deletions.
115 changes: 115 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uuid = { version = "1.4", features = ["fast-rng", "v4", "serde"] }
value-bag = "1.4.1"
tonic = "0.10.2"
prost = "0.12.3"

[dev-dependencies]
tower = { version = "0.4", features = ["util"] }
Expand Down
29 changes: 29 additions & 0 deletions src/domain/models/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use strum_macros::{Display, EnumString};
use uuid::Uuid;

use crate::domain::models::types::AxumErrorResponse;
use crate::grpc::apibara_sink_v1::GetStatusResponse;
use crate::infra::errors::InfraError;

#[derive(Clone, Default, Debug, PartialEq, EnumString, Serialize, Deserialize, Display, Copy)]
Expand Down Expand Up @@ -42,6 +43,28 @@ pub struct IndexerModel {
pub status_server_port: Option<i16>,
}

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct IndexerServerStatus {
pub status: i32,
pub starting_block: Option<u64>,
pub current_block: Option<u64>,
pub head_block: Option<u64>,
#[serde(rename = "reason")]
pub reason_: Option<String>,
}

impl From<GetStatusResponse> for IndexerServerStatus {
fn from(value: GetStatusResponse) -> Self {
Self {
status: value.status,
starting_block: value.starting_block,
current_block: value.current_block,
head_block: value.head_block,
reason_: value.reason,
}
}
}

#[derive(Debug, thiserror::Error)]
pub enum IndexerError {
#[error("internal server error: {0}")]
Expand Down Expand Up @@ -78,6 +101,12 @@ pub enum IndexerError {
InvalidIndexerType(String),
#[error("failed to serialize {0}")]
FailedToSerialize(String),
#[error("indexer status server port not found")]
IndexerStatusServerPortNotFound,
#[error("failed to connect to gRPC server")]
FailedToConnectGRPC(tonic::transport::Error),
#[error("gRPC request failed")]
GRPCRequestFailed(tonic::Status),
}

impl From<diesel::result::Error> for IndexerError {
Expand Down
Loading

0 comments on commit 7fcb8fa

Please sign in to comment.