You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.5 KiB
57 lines
2.5 KiB
//! Configuration for services
|
|
use super::*;
|
|
use std::time::Duration;
|
|
use std::num::NonZeroUsize;
|
|
|
|
/// How long to wait before resetting the restart counter for `StopDirective::Restart`.
|
|
pub const SUPERVISOR_RESTART_TIME_LIMIT: Option<Duration> = Some(Duration::from_secs(5));
|
|
|
|
/// What the supervisor task should do when its background service unexpectedly exits
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Serialize, Deserialize)]
|
|
pub enum StopDirective
|
|
{
|
|
/// Ignore it, allow the service to exit
|
|
Ignore,
|
|
/// Restart the service, either infinitely, or up to this many times before exiting.
|
|
///
|
|
/// If the restart limit is exceeded, exit with error.
|
|
/// The limit is reset every `SUPERVISOR_RESTART_TIME_LIMIT` seconds (or never, if it is `None`.)
|
|
Restart(Option<NonZeroUsize>),
|
|
/// Panic the supervisor
|
|
Panic,
|
|
/// Exit with error
|
|
Error,
|
|
}
|
|
|
|
default!(StopDirective: Self::Error);
|
|
|
|
/// Settings for how a background service runs
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy, Serialize, Deserialize)]
|
|
pub struct ServiceSettings
|
|
{
|
|
// Supervisor controls
|
|
|
|
/// What to do when the supervisor's child task exits unexpectedly
|
|
pub supervisor_stop_directive: StopDirective,
|
|
|
|
// Request dispatching options
|
|
|
|
/// How many requests to batch together
|
|
pub req_dispatch_chunk: NonZeroUsize,
|
|
/// How long to wait before forcefully processing an unfilled batch of requests
|
|
pub req_dispatch_force_timeout: Option<Duration>,
|
|
/// How long to wait before processing batches of requests
|
|
pub req_dispatch_delay: Option<Duration>,
|
|
/// Random **nanosecond** delay bounds between request batch processing
|
|
pub req_dispatch_jitter: Option<(u64, u64)>,
|
|
/// Filter requests in a block based on their lock flags, and process non-locking and locking commands concurrently in 2 seperate tasks.
|
|
/// This may result in commands being processed out-of-order sometimes.
|
|
///
|
|
/// If this is `false`, the lock will be acquired for each block that contains a locking command, then each command will be processed in order within the current task, instead of being filtered and dispatched to the lock-held and the non-lock-held task.
|
|
// For filtering, we can create a type that implements `From<Vec<T>>` and use it as the chunk collection type, maybe, possibly. Idk.
|
|
// Or we can just make a multiplexing mpsc wrapper i guess...
|
|
pub req_dispatch_internal_filter: bool, // Default: true
|
|
}
|
|
|
|
//TODO: impl Default for ServiceSettings
|