parent
85f63cbf5d
commit
dacbea8023
@ -0,0 +1,11 @@
|
||||
use super::*;
|
||||
use config::*;
|
||||
|
||||
/// Builder for a service
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServiceBuilder
|
||||
{
|
||||
/// Settings for the service to use
|
||||
// Boxed because this is a large structure
|
||||
settings: Box<ServiceSettings>,
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
//! 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,
|
||||
}
|
||||
|
||||
impl Default for StopDirective
|
||||
{
|
||||
#[inline]
|
||||
fn default() -> Self
|
||||
{
|
||||
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_hold: usize,
|
||||
/// 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 delay between request batch processing
|
||||
pub req_dispatch_jitter: Option<(Duration, Duration)>,
|
||||
}
|
||||
|
||||
//TODO: impl Default for ServiceSettings
|
Loading…
Reference in new issue