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

Use LazyLock as a replacement for once_cell #37

Merged
merged 1 commit into from
Jul 28, 2024
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
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
Loading