Skip to content

Commit

Permalink
Merge pull request #1 from aradwann/apply-some-enhacements
Browse files Browse the repository at this point in the history
Apply some enhacements
  • Loading branch information
mahsayedsalem authored Nov 18, 2023
2 parents 99ddf29 + a2ddeb0 commit 1035ee0
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 225 deletions.
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use an existing Rust image as the base
FROM rust:latest
# Stage 1: Builder
FROM rust:latest as builder

# Set the working directory
WORKDIR /app
Expand All @@ -10,5 +10,11 @@ COPY . .
# Build the application in release mode
RUN cargo build --release

# Stage 2: Runtime
FROM debian:bookworm-slim

# Copy the built binary from the builder stage to the runtime stage
COPY --from=builder /app/target/release/server_main /usr/local/bin/server_main

# Set the command to run the binary
CMD ["./target/release/server_main"]
CMD ["server_main"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# run using `docker-compose up --scale bader-db=3`
# run using `docker compose up --scale bader-db=3`

version: '3'
services:
Expand Down
2 changes: 1 addition & 1 deletion src/bin/fill_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ fn main() {
.expect("ls command failed to start");
}
println!("Terminated.");
}
}
10 changes: 8 additions & 2 deletions src/bin/server_main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bader_db::run_server;
use anyhow::Result;
use bader_db::run_server;
use std::time::Duration;

#[tokio::main]
Expand All @@ -9,6 +9,12 @@ pub async fn main() -> Result<()> {
let sample = 10;
let threshold = 0.5;
let frequency = Duration::from_millis(100);
run_server(format!("0.0.0.0:{}", port).as_str(), sample, threshold, frequency).await;
run_server(
format!("0.0.0.0:{}", port).as_str(),
sample,
threshold,
frequency,
)
.await;
Ok(())
}
5 changes: 4 additions & 1 deletion src/cache/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ mod tests {
let expired_instant = Instant::now() - Duration::from_secs(5);
let expired_expiry = Expiry::new(expired_instant);
let expired_entry = Entry::new(value.clone(), expired_expiry);
assert_eq!(expired_entry.expiration().remaining(), Some(Duration::from_nanos(0)));
assert_eq!(
expired_entry.expiration().remaining(),
Some(Duration::from_nanos(0))
);
}
}
15 changes: 5 additions & 10 deletions src/cache/expiry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub struct Expiry {

impl Expiry {
pub fn new<I>(instant: I) -> Self
where
I: Into<Instant>,
where
I: Into<Instant>,
{
Self {
instant: Some(instant.into()),
Expand Down Expand Up @@ -60,13 +60,9 @@ impl From<(u64, &String)> for Expiry {
let format = expiry.1;
let expiry_type = format.to_ascii_lowercase().as_str().into();
match expiry_type {
ExpiryFormat::PX => {
Duration::from_millis(amount).into()
} ,
ExpiryFormat::EX => {
Duration::from_secs(amount).into()
},
_ => Self{ instant: None},
ExpiryFormat::PX => Duration::from_millis(amount).into(),
ExpiryFormat::EX => Duration::from_secs(amount).into(),
_ => Self { instant: None },
}
}
}
Expand Down Expand Up @@ -95,7 +91,6 @@ impl From<&str> for ExpiryFormat {
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 1035ee0

Please sign in to comment.