From ecaf0a691333256c1525f66030d9ca92f72ac400 Mon Sep 17 00:00:00 2001 From: Bruno Paulino Date: Sun, 28 Jul 2024 23:47:27 +0200 Subject: [PATCH] Use LazyLock as a replacement for once_cell --- Cargo.lock | 1 - Cargo.toml | 5 ++--- Dockerfile | 4 ++-- src/routes/artifacts.rs | 4 ++-- src/startup.rs | 6 +++++- tests/e2e/helpers.rs | 10 +++++----- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98c199b..23d4ae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -533,7 +533,6 @@ dependencies = [ "actix-web", "dotenv", "futures", - "once_cell", "openssl", "reqwest", "rust-s3", diff --git a/Cargo.toml b/Cargo.toml index cedcf2b..f0525b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,14 +20,13 @@ tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1", features = ["log"] } tracing-appender = "0.2.3" tracing-subscriber = { version = "0.3.18", features = [ - "registry", - "env-filter", + "registry", + "env-filter", ] } tracing-log = "0.2.0" tracing-bunyan-formatter = "0.3.9" futures = "0.3.30" openssl = { version = "0.10.66", features = ["vendored"] } -once_cell = "1.19.0" [dev-dependencies] reqwest = "0.11.23" diff --git a/Dockerfile b/Dockerfile index affd18a..8ab9952 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ # let's cross-compile using musl so the binary is statically linked with the right dependencies # See: https://users.rust-lang.org/t/unable-to-run-compiled-program/88441/5 # See: https://github.com/rust-cross/rust-musl-cross -# See: https://hub.docker.com/layers/messense/rust-musl-cross/x86_64-musl/images/sha256-d3c1fbd71e737fe988bd7a141c171c8f4b5a7d072a0c84a58720fdf7cf4ded24?context=explore -FROM messense/rust-musl-cross@sha256:9bf63830ce63649fb54995c5fbbd36b993535208000909ad4f9993bf6e168154 as builder +# See: https://hub.docker.com/layers/messense/rust-musl-cross/x86_64-musl/images/sha256-740c62dd2e08746df5fafa3fa47f5f2b0afb231c911e8b929c584d93c3baacae?context=explore +FROM messense/rust-musl-cross@sha256:47306f9557003a9cb1c63f5229c8276bc75e3bcf2be51e0d00f4abcc65fffaa4 as builder WORKDIR /app COPY . /app RUN cargo build --verbose --release diff --git a/src/routes/artifacts.rs b/src/routes/artifacts.rs index bac533d..7759230 100644 --- a/src/routes/artifacts.rs +++ b/src/routes/artifacts.rs @@ -60,8 +60,8 @@ pub async fn put_file(req: HttpRequest, storage: Data, body: Bytes) -> HttpResponse::Created().json(artifact) } - Err(e) => { - eprintln!("Something went wrong {}", e); + Err(error) => { + tracing::error!("Could not store file error={}", error); HttpResponse::BadRequest().finish() } } diff --git a/src/startup.rs b/src/startup.rs index c9aba61..063ea7e 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -12,6 +12,10 @@ use crate::{ pub fn run(listener: TcpListener, app_settings: AppSettings) -> Result { let storage = Storage::new(&app_settings); let storage = web::Data::new(storage); + let port = listener + .local_addr() + .expect("TCPListener should be valid") + .port(); let server = HttpServer::new(move || { App::new() .wrap(Logger::default()) @@ -30,7 +34,7 @@ pub fn run(listener: TcpListener, app_settings: AppSettings) -> Result TestApp { dotenv().ok(); - Lazy::force(&TRACING); + + LazyLock::force(&TRACING); let storage_server = MockServer::start().await; @@ -45,7 +45,7 @@ pub async fn spawn_app() -> TestApp { } } -static TRACING: Lazy<()> = Lazy::new(|| { +static TRACING: LazyLock<()> = LazyLock::new(|| { let subscriber_name = "test"; let filter_level = String::from("debug");