mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
fix(send): migrate rand usage to the 0.10 API
rand 0.10 renamed the entry points dependabot's version bump alone cannot follow: `thread_rng()` -> `rng()`, `gen_range()` -> `random_range()` and the `Rng` trait -> `RngExt`. The jitter only needs one float, so use the free function `rand::random_range(0.2..0.8)` and drop the now-unused trait import instead of importing `RngExt`. Verified: cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --locked (retry_delay_seconds_bounds keeps the 0.2..0.8 jitter window).
This commit is contained in:
@@ -17,7 +17,6 @@ use crate::link_cache::{CachedMedia, CachedMediaKind, CachedPost};
|
|||||||
use crate::media_sender::MediaSender;
|
use crate::media_sender::MediaSender;
|
||||||
use input_media::{build_media_group, input_file_for, item_url};
|
use input_media::{build_media_group, input_file_for, item_url};
|
||||||
use post_send::{cache_animation_send, cache_sent_task};
|
use post_send::{cache_animation_send, cache_sent_task};
|
||||||
use rand::Rng;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use teloxide::prelude::*;
|
use teloxide::prelude::*;
|
||||||
@@ -261,7 +260,7 @@ pub fn photos_first(items: Vec<MediaItemPayload>) -> Vec<MediaItemPayload> {
|
|||||||
|
|
||||||
/// Exponential backoff with jitter, capped at 30s.
|
/// Exponential backoff with jitter, capped at 30s.
|
||||||
pub fn retry_delay_seconds(attempts: u32) -> f64 {
|
pub fn retry_delay_seconds(attempts: u32) -> f64 {
|
||||||
let jitter: f64 = rand::thread_rng().gen_range(0.2..0.8);
|
let jitter: f64 = rand::random_range(0.2..0.8);
|
||||||
(2f64.powi(attempts as i32) + jitter).min(30.0)
|
(2f64.powi(attempts as i32) + jitter).min(30.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user