sui_bridge/sui_bridge_watchdog/
sui_bridge_status.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! The SuiBridgeStatus observable monitors whether the Sui Bridge is paused.

use crate::sui_bridge_watchdog::Observable;
use crate::sui_client::SuiBridgeClient;
use async_trait::async_trait;
use prometheus::IntGauge;
use std::sync::Arc;

use tokio::time::Duration;
use tracing::{error, info};

pub struct SuiBridgeStatus {
    sui_client: Arc<SuiBridgeClient>,
    metric: IntGauge,
}

impl SuiBridgeStatus {
    pub fn new(sui_client: Arc<SuiBridgeClient>, metric: IntGauge) -> Self {
        Self { sui_client, metric }
    }
}

#[async_trait]
impl Observable for SuiBridgeStatus {
    fn name(&self) -> &str {
        "SuiBridgeStatus"
    }

    async fn observe_and_report(&self) {
        let status = self.sui_client.is_bridge_paused().await;
        match status {
            Ok(status) => {
                self.metric.set(status as i64);
                info!("Sui Bridge Status: {:?}", status);
            }
            Err(e) => {
                error!("Error getting sui bridge status: {:?}", e);
            }
        }
    }

    fn interval(&self) -> Duration {
        Duration::from_secs(10)
    }
}