Skip to content

Commit

Permalink
graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw committed May 24, 2024
1 parent 6c70cc5 commit 520ec90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/bin/relayer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod importer_online;

use stratus::config::ExternalRelayerConfig;
use stratus::GlobalServices;
use stratus::{GlobalServices, GlobalState};

const TASK_NAME: &str = "relayer";

fn main() -> anyhow::Result<()> {
let global_services = GlobalServices::<ExternalRelayerConfig>::init()?;
Expand All @@ -14,6 +16,10 @@ async fn run(config: ExternalRelayerConfig) -> anyhow::Result<()> {
let relayer = config.relayer.init().await?;

loop {
if GlobalState::warn_if_shutdown(TASK_NAME) {
return Ok(());
};

let block_number = match relayer.relay_next_block().await {
Ok(bnum) => bnum,
Err(err) => {
Expand Down
11 changes: 5 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,16 @@ impl ExternalRelayerClientConfig {
}

#[derive(Parser, DebugAsJson, Clone, serde::Serialize)]
#[group(requires_all = ["url", "connections", "acquire_timeout", "forward_to", "backoff"])]
pub struct ExternalRelayerServerConfig {
#[arg(long = "relayer-db-url", env = "RELAYER_DB_URL", required = false)]
#[arg(long = "relayer-db-url", env = "RELAYER_DB_URL")]
pub url: String,
#[arg(long = "relayer-db-connections", env = "RELAYER_DB_CONNECTIONS", required = false)]
#[arg(long = "relayer-db-connections", env = "RELAYER_DB_CONNECTIONS", default_value = "5")]
pub connections: u32,
#[arg(long = "relayer-db-timeout", value_parser=parse_duration, env = "RELAYER_DB_TIMEOUT", required = false)]
#[arg(long = "relayer-db-timeout", value_parser=parse_duration, env = "RELAYER_DB_TIMEOUT", default_value = "1s")]
pub acquire_timeout: Duration,
#[arg(long = "relayer-forward-to", env = "RELAYER_FORWARD_TO", required = false)]
#[arg(long = "relayer-forward-to", env = "RELAYER_FORWARD_TO")]
pub forward_to: String,
#[arg(long = "relayer-db-backoff", value_parser=parse_duration, env = "RELAYER_DB_BACKOFF", required = false)]
#[arg(long = "relayer-db-backoff", value_parser=parse_duration, env = "RELAYER_DB_BACKOFF", default_value = "10ms")]
pub backoff: Duration,
}

Expand Down

0 comments on commit 520ec90

Please sign in to comment.