Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
chore: improve --embedded-database messaging (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 authored Oct 14, 2023
1 parent 560fc8e commit 8ba2936
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/fuel-indexer/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ pub async fn exec(args: IndexerArgs) -> anyhow::Result<()> {
..Default::default()
};

println!(
r#"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Warning: Using the --embedded-database flag is experimental and should only be used for local development.
If the --embedded-database flag demonstrates flaky behavior on your machine, or doesn't work altogether, we recommend that you simply use the provided docker compose file here:
https://github.com/FuelLabs/fuel-indexer/blob/develop/scripts/docker-compose.yaml.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"#
);

forc_postgres::commands::create::exec(create_db_cmd).await?;
}

Expand Down
30 changes: 28 additions & 2 deletions plugins/forc-index/src/ops/forc_index_start.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::cli::StartCommand;
use fuel_indexer_lib::defaults;
use std::{ffi::OsStr, process::Command};
use std::{
ffi::OsStr,
process::{Command, Stdio},
};
use tracing::info;

pub async fn init(command: StartCommand) -> anyhow::Result<()> {
Expand Down Expand Up @@ -125,7 +128,7 @@ pub async fn init(command: StartCommand) -> anyhow::Result<()> {
("--postgres-user", postgres_user),
("--postgres-password", postgres_password),
("--postgres-host", postgres_host),
("--postgres-port", postgres_port),
("--postgres-port", postgres_port.clone()),
("--postgres-database", postgres_database),
];

Expand All @@ -149,6 +152,29 @@ pub async fn init(command: StartCommand) -> anyhow::Result<()> {
Ok(child) => {
let pid = child.id();
info!("✅ Successfully started the indexer service at PID {pid}");

// Ensure that the DB actually was created if we passed --embedded-database
if embedded_database {
std::thread::sleep(std::time::Duration::from_secs(1));
let port = postgres_port.unwrap_or(defaults::POSTGRES_PORT.to_string());
let mut cmd = Command::new("lsof");
cmd.arg(&format!("-ti:{}", port))
.stdout(Stdio::piped())
.stderr(Stdio::piped());

if verbose {
info!("{cmd:?}");
}

match cmd.spawn() {
Ok(child) => {
let output = child.wait_with_output().unwrap();
let pid = String::from_utf8(output.stdout).unwrap();
info!("✅ Successfully confirmed the embedded database process at PID(s) {pid}");
}
Err(e) => panic!("❌ Failed to confirm that --embedded-database was started: {e:?}."),
}
}
}
Err(e) => panic!("❌ Failed to spawn fuel-indexer child process: {e:?}."),
}
Expand Down

0 comments on commit 8ba2936

Please sign in to comment.