fix: launch API server in background

This commit is contained in:
Aravinth Manivannan 2023-10-04 19:04:47 +05:30
parent 501f44560c
commit b3a3fe8c0d
Signed by: realaravinth
GPG key ID: F8F50389936984FF
2 changed files with 14 additions and 11 deletions

View file

@ -47,12 +47,13 @@ semver = { version = "1.0.18", features = ["serde"] }
toml = "0.7.6"
tokio = { version = "1.32.0", features = ["sync", "time"] }
clap = { version = "4.4.6", features = ["derive"] }
actix-rt = "2.7.0"
[build-dependencies]
serde_json = "1"
sqlx = { version = "0.6.1", features = [ "runtime-actix-rustls", "postgres", "time", "offline"] }
[dev-dependencies]
actix-rt = "2.7.0"
#actix-rt = "2.7.0"
base64 = "0.13.0"
mktemp = "0.5.1"

View file

@ -90,7 +90,7 @@ async fn main() -> std::io::Result<()> {
}
Command::Test { path } => {
let ctx: Arc<dyn MinAppContext> = Arc::new(CliCtx::new());
let serv = basic_server(ctx.clone()).await;
crate::runner::suite::SuiteRunnerState::run_proxy(ctx.as_ref());
let (suite_results, init_containers) =
crate::runner::target::run_target(ctx.as_ref(), path.clone()).await;
@ -104,6 +104,7 @@ async fn main() -> std::io::Result<()> {
std::fs::write(results_file, serde_json::to_string(&content).unwrap()).unwrap();
crate::runner::suite::SuiteRunnerState::stop_proxy(ctx.as_ref());
serv.stop(true).await;
Ok(())
}
}
@ -128,14 +129,14 @@ async fn run_daemon() -> std::io::Result<()> {
Ok(())
}
async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> {
let ip = "0.0.0.0:29130";
info!("Starting server on: http://{}", ip);
HttpServer::new(move || {
async fn basic_server(ctx: Arc<dyn MinAppContext>) -> actix_web::dev::ServerHandle {
let ctx = AppMinCtx::new(ctx);
info!("Starting server on: http://0.0.0.0:29130");
let serv = HttpServer::new(move || {
App::new()
.wrap(TracingLogger::default())
.wrap(actix_middleware::Compress::default())
.app_data(ctx2.clone())
.app_data(ctx.clone())
.app_data(get_json_err())
.wrap(
actix_middleware::DefaultHeaders::new()
@ -146,11 +147,12 @@ async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> {
))
.configure(services)
})
.bind(ip)
.bind("0.0.0.0:29130")
.unwrap()
.run()
.await?;
Ok(())
.run();
let handle = serv.handle();
tokio::spawn(serv);
handle
}
async fn daemon(ctx: AppFullCtx, ctx2: AppMinCtx) -> std::io::Result<()> {