Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve --embedded-database messaging #1407

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -120,7 +123,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 @@ -144,6 +147,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
Loading