Skip to main content

IdleBackoff

Struct IdleBackoff 

Source
pub struct IdleBackoff { /* private fields */ }
Available on crate feature cronutil only.
Expand description

空轮指数退避闸门: 连续空轮时按指数延长下次允许执行的间隔, 有新待办立即清零恢复高频。 状态只在进程内存, 不需要跨重启持久化

Implementations§

Source§

impl IdleBackoff

Source

pub fn new(base: Duration, max: Duration) -> Self

base 为首次空轮后的退避间隔 (零时按 1s), max 为上限 (小于 base 时取 base); 如 2s 起步、翻倍增长、封顶 60s

Source

pub fn should_run(&self) -> bool

本轮 tick 是否允许执行; 仍在退避窗口内时返回 false, 调用方直接返回, 不查库

Source

pub fn hit(&self)

报告本轮有待办被处理: 清零退避, 恢复高频扫描

Source

pub fn miss(&self)

报告本轮空转: 退避间隔翻倍 (首次为 base, 封顶 max), 推迟下次允许执行的时间

Source

pub fn reset(&self)

清空退避状态, 用于管理员手动触发时绕过退避窗口强制执行

Source

pub fn current(&self) -> Duration

当前退避间隔 (零表示无退避), 便于监控展示

Trait Implementations§

Source§

impl Debug for IdleBackoff

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for IdleBackoff

§

impl Forget for IdleBackoff

§

impl Move for IdleBackoff

§

impl RefUnwindSafe for IdleBackoff
where Mutex<State>: RefUnwindSafe,

§

impl Send for IdleBackoff
where Mutex<State>: Send,

§

impl Sync for IdleBackoff
where Mutex<State>: Sync,

§

impl Unpin for IdleBackoff
where Align4<u32>: Unpin, Align1<u8>: Unpin,

§

impl UnsafeUnpin for IdleBackoff
where Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin,

§

impl UnwindSafe for IdleBackoff
where Mutex<State>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.