Skip to content

Commit

Permalink
Use LazyLock as a replacement for once_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
brunojppb committed Jul 28, 2024
1 parent df5a301 commit ecaf0a6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/routes/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub async fn put_file(req: HttpRequest, storage: Data<Storage>, 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()
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use crate::{
pub fn run(listener: TcpListener, app_settings: AppSettings) -> Result<Server, std::io::Error> {
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())
Expand All @@ -30,7 +34,7 @@ pub fn run(listener: TcpListener, app_settings: AppSettings) -> Result<Server, s
.listen(listener)?
.run();

println!("Decay server started");
tracing::info!(port = port, "Decay server started");

Ok(server)
}
10 changes: 5 additions & 5 deletions tests/e2e/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::net::TcpListener;

use decay::{
app_settings::get_settings,
telemetry::{get_telemetry_subscriber, init_telemetry_subscriber},
};
use dotenv::dotenv;
use std::net::TcpListener;
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use wiremock::MockServer;

pub struct TestApp {
Expand All @@ -21,7 +20,8 @@ pub struct TestApp {
#[allow(clippy::let_underscore_future)]
pub async fn spawn_app() -> TestApp {
dotenv().ok();
Lazy::force(&TRACING);

LazyLock::force(&TRACING);

let storage_server = MockServer::start().await;

Expand All @@ -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");

Expand Down

0 comments on commit ecaf0a6

Please sign in to comment.