mirror of
https://github.com/mailscope/kumomta.git
synced 2026-09-06 10:38:56 +00:00
refactor: rename shutdown/lifetime -> lifecycle
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::lifecycle::{Activity, ShutdownSubcription};
|
||||
use crate::logging::{log_disposition, RecordType};
|
||||
use crate::queue::{Queue, QueueManager};
|
||||
use crate::shutdown::{Activity, ShutdownSubcription};
|
||||
use crate::spool::SpoolManager;
|
||||
use anyhow::Context;
|
||||
use config::load_config;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! This module helps to manage the lifetime of the process
|
||||
//! This module helps to manage the life cycle of the process
|
||||
//! and to shut things down gracefully.
|
||||
//!
|
||||
//! See <https://tokio.rs/tokio/topics/shutdown> for more information.
|
||||
@@ -14,7 +14,7 @@ static STOPPING: OnceCell<ShutdownState> = OnceCell::new();
|
||||
|
||||
/// Represents some activity which cannot be ruthlessly interrupted.
|
||||
/// Obtain an Activity instance via Activity::get(). While any
|
||||
/// Activity instances are alive in the program, Lifetime::wait_for_shutdown
|
||||
/// Activity instances are alive in the program, LifeCycle::wait_for_shutdown
|
||||
/// cannot complete.
|
||||
#[derive(Clone)]
|
||||
pub struct Activity {
|
||||
@@ -35,10 +35,14 @@ impl Activity {
|
||||
Some(ACTIVE.get()?.lock().unwrap().as_ref()?.clone())
|
||||
}
|
||||
|
||||
/// Obtain an Activity instance.
|
||||
/// Returns Err if the process is shutting down and no new
|
||||
/// activity can be initiated
|
||||
pub fn get() -> anyhow::Result<Self> {
|
||||
Self::get_opt().ok_or_else(|| anyhow::anyhow!("shutting down"))
|
||||
}
|
||||
|
||||
/// Returns true if the process is shutting down.
|
||||
pub fn is_shutting_down(&self) -> bool {
|
||||
SHUTTING_DOWN.load(Ordering::Relaxed)
|
||||
}
|
||||
@@ -72,17 +76,16 @@ impl ShutdownSubcription {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Lifetime struct represents the lifetime of this server process.
|
||||
/// The LifeCycle struct represents the life_cycle of this server process.
|
||||
/// Creating an instance of it will prepare the global state of the
|
||||
/// process and allow other code to work with Activity and ShutdownSubcription.
|
||||
///
|
||||
pub struct Lifetime {
|
||||
pub struct LifeCycle {
|
||||
activity_rx: MPSCReceiver<()>,
|
||||
request_shutdown_rx: MPSCReceiver<()>,
|
||||
}
|
||||
|
||||
impl Lifetime {
|
||||
/// Initialize the process lifetime.
|
||||
impl LifeCycle {
|
||||
/// Initialize the process life_cycle.
|
||||
/// May be called only once; will panic if called multiple times.
|
||||
pub fn new() -> Self {
|
||||
let (activity_tx, activity_rx) = tokio::sync::mpsc::channel(1);
|
||||
@@ -111,7 +114,7 @@ impl Lifetime {
|
||||
|
||||
/// Request that we shutdown the process.
|
||||
/// This will cause the wait_for_shutdown method on the process
|
||||
/// Lifetime instance to wake up and initiate the shutdown
|
||||
/// LifeCycle instance to wake up and initiate the shutdown
|
||||
/// procedure.
|
||||
pub async fn request_shutdown() {
|
||||
if let Some(state) = STOPPING.get() {
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::shutdown::Lifetime;
|
||||
use crate::lifecycle::LifeCycle;
|
||||
use anyhow::Context;
|
||||
use caps::{CapSet, Capability, CapsHashSet};
|
||||
use clap::Parser;
|
||||
@@ -10,12 +10,12 @@ use tracing_subscriber::{fmt, EnvFilter};
|
||||
|
||||
mod dest_site;
|
||||
mod http_server;
|
||||
mod lifecycle;
|
||||
mod logging;
|
||||
mod metrics_helper;
|
||||
mod mod_kumo;
|
||||
mod queue;
|
||||
mod runtime;
|
||||
mod shutdown;
|
||||
mod smtp_server;
|
||||
mod spool;
|
||||
|
||||
@@ -114,17 +114,17 @@ async fn run(opts: Opt) -> anyhow::Result<()> {
|
||||
config::set_policy_path(policy).await?;
|
||||
}
|
||||
|
||||
let mut lifetime = Lifetime::new();
|
||||
let mut life_cycle = LifeCycle::new();
|
||||
|
||||
let mut config = config::load_config().await?;
|
||||
config.async_call_callback("init", ()).await?;
|
||||
|
||||
if let Err(err) = crate::spool::SpoolManager::get().await.start_spool().await {
|
||||
tracing::error!("problem starting spool: {err:#}");
|
||||
Lifetime::request_shutdown().await;
|
||||
LifeCycle::request_shutdown().await;
|
||||
}
|
||||
|
||||
lifetime.wait_for_shutdown().await;
|
||||
life_cycle.wait_for_shutdown().await;
|
||||
|
||||
// after waiting for those to idle out, shut down logging
|
||||
crate::logging::Logger::signal_shutdown().await;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::dest_site::DestSiteConfig;
|
||||
use crate::http_server::HttpListenerParams;
|
||||
use crate::lifecycle::LifeCycle;
|
||||
use crate::logging::LogFileParams;
|
||||
use crate::queue::QueueConfig;
|
||||
use crate::shutdown::Lifetime;
|
||||
use crate::smtp_server::{EsmtpListenerParams, RejectError};
|
||||
use config::get_or_create_module;
|
||||
use mlua::{Function, Lua, LuaSerdeExt, Value};
|
||||
@@ -62,7 +62,7 @@ pub fn register(lua: &Lua) -> anyhow::Result<()> {
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = define_spool(params).await {
|
||||
tracing::error!("Error in spool: {err:#}");
|
||||
Lifetime::request_shutdown().await;
|
||||
LifeCycle::request_shutdown().await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::dest_site::SiteManager;
|
||||
use crate::lifecycle::{Activity, ShutdownSubcription};
|
||||
use crate::logging::{log_disposition, RecordType};
|
||||
use crate::shutdown::{Activity, ShutdownSubcription};
|
||||
use crate::spool::SpoolManager;
|
||||
use chrono::Utc;
|
||||
use config::load_config;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::dest_site::ResolvedAddress;
|
||||
use crate::lifecycle::{Activity, ShutdownSubcription};
|
||||
use crate::logging::{log_disposition, RecordType};
|
||||
use crate::queue::QueueManager;
|
||||
use crate::shutdown::{Activity, ShutdownSubcription};
|
||||
use crate::spool::{SpoolHandle, SpoolManager};
|
||||
use anyhow::{anyhow, Context};
|
||||
use chrono::Utc;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::lifecycle::Activity;
|
||||
use crate::logging::{log_disposition, RecordType};
|
||||
use crate::mod_kumo::{DefineSpoolParams, SpoolKind};
|
||||
use crate::queue::QueueManager;
|
||||
use crate::shutdown::Activity;
|
||||
use anyhow::Context;
|
||||
use chrono::Utc;
|
||||
use message::Message;
|
||||
|
||||
Reference in New Issue
Block a user