cat_gateway/service/utilities/health/
live.rs

1//! Utilities used for `Liveness` functionality.
2
3use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
4
5/// Flag to determine if the service is live.
6///
7/// Defaults to `true`.
8static IS_LIVE: AtomicBool = AtomicBool::new(true);
9
10/// Timestamp in seconds used to determine if the service is live.
11static LIVE_PANIC_COUNTER: AtomicU64 = AtomicU64::new(0);
12
13/// Get the `IS_LIVE` flag.
14pub(crate) fn is_live() -> bool {
15    IS_LIVE.load(Ordering::Acquire)
16}
17
18/// Set the `IS_LIVE` flag to `false`.
19pub(crate) fn set_not_live() {
20    IS_LIVE.store(false, Ordering::Release);
21}
22
23/// Get the `LIVE_PANIC_COUNTER` value.
24pub(crate) fn get_live_counter() -> u64 {
25    LIVE_PANIC_COUNTER.load(Ordering::SeqCst)
26}
27
28/// Increase `LIVE_PANIC_COUNTER` by one.
29pub(crate) fn inc_live_counter() {
30    LIVE_PANIC_COUNTER.fetch_add(1, Ordering::SeqCst);
31}
32
33/// Reset the `LIVE_PANIC_COUNTER` to zero, returns last count.
34pub(crate) fn live_counter_reset() -> u64 {
35    LIVE_PANIC_COUNTER.swap(0, Ordering::SeqCst)
36}