diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5c62256..16f24ff 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,6 +2,11 @@ name: Lint & Test on: pull_request: types: [opened, edited, reopened, synchronize] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: test: strategy: @@ -9,42 +14,22 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - name: Install Rust Stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - - name: Install Cargo - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - components: clippy - - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Cache cargo registry - uses: actions/cache@v1 - with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + - name: Install Rust Stable + uses: dtolnay/rust-toolchain@stable - - name: Cache cargo index - uses: actions/cache@v1 + - name: Rust Cache + uses: Swatinem/rust-cache@v2 with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + key: ${{ matrix.platform }}-v2 - - name: Cache cargo build - uses: actions/cache@v1 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - name: Clippy Install + uses: dtolnay/rust-toolchain@clippy - name: Lint - uses: actions-rs/clippy@master - with: - args: --all-features --all-targets + run: cargo clippy --all-features --all-targets --tests - name: Test - run: cargo test --all-features + run: cargo test --all-features \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 3e0e826..0552261 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "backoff-rs" version = "0.1.0" -edition = "2018" +edition = "2024" authors = ["Dean Karn "] description = "Backoff provides the base components for implementing backoff and retry operations." keywords = [ @@ -15,4 +15,4 @@ repository = "https://github.com/rust-playground/backoff-rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rand = "0.8.4" +rand = "0.9.0" diff --git a/src/lib.rs b/src/lib.rs index 0222ce4..eb4eae7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ impl Exponential { /// returns the calculated backoff duration for backoff and retries based on the attempt. pub fn duration(&self, attempt: usize) -> Duration { let nanoseconds = (self.factor.powi(attempt as i32) * self.interval - + rand::thread_rng().gen_range(0.0..=self.jitter)) as u64; + + rand::rng().random_range(0.0..=self.jitter)) as u64; match self.max { Some(max) if nanoseconds > max => Duration::from_nanos(max), _ => Duration::from_nanos(nanoseconds),