Skip to content

Commit

Permalink
fix: drop the manager handler correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gusinacio committed Dec 13, 2023
1 parent 39ed8d1 commit 9f7bb23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions tap-agent/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
tap::sender_allocation_relationships_manager::SenderAllocationRelationshipsManager,
};

pub async fn start_agent(config: &'static config::Cli) {
pub async fn start_agent(config: &'static config::Cli) -> SenderAllocationRelationshipsManager {
let pgpool = database::connect(&config.postgres).await;

let http_client = reqwest::Client::new();
Expand Down Expand Up @@ -79,7 +79,7 @@ pub async fn start_agent(config: &'static config::Cli) {
verifying_contract: config.receipts.receipts_verifier_address,
};

let _sender_allocation_relationships_manager = SenderAllocationRelationshipsManager::new(
SenderAllocationRelationshipsManager::new(
config,
pgpool,
indexer_allocations,
Expand All @@ -88,5 +88,5 @@ pub async fn start_agent(config: &'static config::Cli) {
tap_eip712_domain_separator,
sender_aggregator_endpoints,
)
.await;
.await
}
27 changes: 15 additions & 12 deletions tap-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ async fn main() -> Result<()> {
lazy_static::initialize(&CONFIG);
debug!("Config: {:?}", *CONFIG);

agent::start_agent(&CONFIG).await;
info!("TAP Agent started.");

// Have tokio wait for SIGTERM or SIGINT.
let mut signal_sigint = signal(SignalKind::interrupt())?;
let mut signal_sigterm = signal(SignalKind::terminate())?;
tokio::select! {
_ = signal_sigint.recv() => debug!("Received SIGINT."),
_ = signal_sigterm.recv() => debug!("Received SIGTERM."),
{
let _manager = agent::start_agent(&CONFIG).await;
info!("TAP Agent started.");

// Have tokio wait for SIGTERM or SIGINT.
let mut signal_sigint = signal(SignalKind::interrupt())?;
let mut signal_sigterm = signal(SignalKind::terminate())?;
tokio::select! {
_ = signal_sigint.recv() => debug!("Received SIGINT."),
_ = signal_sigterm.recv() => debug!("Received SIGTERM."),
}

// If we're here, we've received a signal to exit.
info!("Shutting down...");
}

// If we're here, we've received a signal to exit.
info!("Shutting down...");
// Manager should be successfully dropped here.

// Stop the server and wait for it to finish gracefully.
debug!("Goodbye!");
Expand Down

0 comments on commit 9f7bb23

Please sign in to comment.