Skip to content

Commit

Permalink
fix: try to fix anda_bot bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jan 23, 2025
1 parent 52c99b7 commit c40db91
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion agents/anda_bot/nitro_enclave/amd64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN mv linux-amd64/dnsproxy ./ && chmod +x dnsproxy
RUN wget -O ic_tee_nitro_gateway https://github.com/ldclabs/ic-tee/releases/download/v0.2.11/ic_tee_nitro_gateway
RUN chmod +x ic_tee_nitro_gateway

RUN wget -O anda_bot https://github.com/ldclabs/anda/releases/download/v0.2.8/anda_bot
RUN wget -O anda_bot https://github.com/ldclabs/anda/releases/download/v0.2.9/anda_bot
RUN chmod +x anda_bot

FROM --platform=linux/amd64 debian:bookworm-slim AS runtime
Expand Down
59 changes: 35 additions & 24 deletions agents/anda_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,41 @@ struct Cli {
}

// cargo run -p anda_bot -- --port 8042 --config agents/anda_bot/nitro_enclave/Config.toml --character agents/anda_bot/nitro_enclave/Character.toml
#[tokio::main]
async fn main() -> Result<(), BoxError> {
let cli = Cli::parse();

let writer = if let Some(logtail) = &cli.logtail {
let stream = TcpStream::connect(logtail).await?;
stream.writable().await?;
new_writer(stream)
} else {
new_writer(tokio::io::stdout())
};
Builder::with_level(&get_env_level().to_string())
.with_target_writer("*", writer)
.init();

log::info!(target: LOG_TARGET, "bootstrap {}@{}", APP_NAME, APP_VERSION);
match bootstrap(cli).await {
Ok(_) => Ok(()),
Err(err) => {
log::error!(target: LOG_TARGET, "bootstrap error: {:?}", err);
tokio::time::sleep(Duration::from_secs(3)).await;
Err(err)
}
}
fn main() -> Result<(), BoxError> {
let default_stack_size = 2 * 1024 * 1024;
let stack_size = std::env::var("RUST_MIN_STACK")
.map(|s| s.parse().expect("RUST_MIN_STACK must be a valid number"))
.unwrap_or(default_stack_size);

tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_stack_size(stack_size)
.build()
.unwrap()
.block_on(async {
let cli = Cli::parse();

let writer = if let Some(logtail) = &cli.logtail {
let stream = TcpStream::connect(logtail).await?;
stream.writable().await?;
new_writer(stream)
} else {
new_writer(tokio::io::stdout())
};
Builder::with_level(&get_env_level().to_string())
.with_target_writer("*", writer)
.init();

log::info!(target: LOG_TARGET, "bootstrap {}@{}", APP_NAME, APP_VERSION);
match bootstrap(cli).await {
Ok(_) => Ok(()),
Err(err) => {
log::error!(target: LOG_TARGET, "bootstrap error: {:?}", err);
tokio::time::sleep(Duration::from_secs(3)).await;
Err(err)
}
}
})
}

async fn bootstrap(cli: Cli) -> Result<(), BoxError> {
Expand Down

0 comments on commit c40db91

Please sign in to comment.