pub struct AppState {Show 20 fields
pub gpu_pool: Arc<GpuPool>,
pub queue_capacity: usize,
pub model_cache: Arc<Mutex<ModelCache>>,
pub active_generation: Arc<RwLock<Option<ActiveGenerationSnapshot>>>,
pub config: Arc<RwLock<Config>>,
pub start_time: Instant,
pub model_load_lock: Arc<Mutex<()>>,
pub pull_lock: Arc<Mutex<()>>,
pub chain_lock: Arc<Mutex<()>>,
pub queue: QueueHandle,
pub job_registry: SharedJobRegistry,
pub shared_pool: Arc<Mutex<SharedPool>>,
pub shutdown_tx: Arc<Mutex<Option<Sender<()>>>>,
pub upscaler_cache: Arc<Mutex<Option<Box<dyn UpscaleEngine>>>>,
pub metadata_db: Arc<Option<MetadataDb>>,
pub downloads: Arc<DownloadQueue>,
pub resources: Arc<ResourceBroadcaster>,
pub catalog_live_cache: LiveCache,
pub catalog_live_civitai_base: Arc<String>,
pub catalog_intents: Arc<RwLock<HashMap<String, CatalogModelIntent>>>,
}Fields§
§gpu_pool: Arc<GpuPool>GPU worker pool for multi-GPU dispatch.
queue_capacity: usizeMaximum queue capacity (for status reporting and 503 responses).
model_cache: Arc<Mutex<ModelCache>>§active_generation: Arc<RwLock<Option<ActiveGenerationSnapshot>>>Uses std::sync::RwLock (not tokio) because it’s only accessed from synchronous contexts (inside spawn_blocking closures and brief reads). Must never be held across an .await point.
config: Arc<RwLock<Config>>§start_time: Instant§model_load_lock: Arc<Mutex<()>>Guards concurrent model loads and hot-swaps.
pull_lock: Arc<Mutex<()>>Guards concurrent pulls — only one download at a time.
chain_lock: Arc<Mutex<()>>Serializes chained video renders. The chain handler removes the
engine from model_cache and runs blocking work outside that
lock for the full multi-minute chain; without a dedicated lock two
concurrent chain requests race on cache.take() and the loser
surfaces “engine vanished from cache after ensure_model_ready”.
Held for the entire chain (load + all stages + restore); other
single-clip requests continue to queue normally on queue.
queue: QueueHandleGeneration request queue.
job_registry: SharedJobRegistryAuthoritative registry of in-flight jobs (queued + running). Powers
GET /api/queue so the SPA can reconcile persisted “running” cards
against server reality and dead-letter zombies whose SSE stream
silently dropped.
Shared tokenizer pool for cross-engine caching.
shutdown_tx: Arc<Mutex<Option<Sender<()>>>>Shutdown trigger for graceful shutdown via /api/shutdown endpoint.
upscaler_cache: Arc<Mutex<Option<Box<dyn UpscaleEngine>>>>Cached upscaler engine to avoid recreating per request. Small models (2-64MB), single slot.
metadata_db: Arc<Option<MetadataDb>>SQLite-backed gallery metadata store. None when MOLD_DB_DISABLE=1 or
when MOLD_HOME could not be resolved — callers must fall back to the
filesystem walk in routes::scan_gallery_dir.
downloads: Arc<DownloadQueue>Single-writer download queue.
resources: Arc<ResourceBroadcaster>Always-on resource telemetry (Agent B).
catalog_live_cache: LiveCacheIn-process TTL cache backing /api/catalog/search.
catalog_live_civitai_base: Arc<String>Upstream base URL for live Civitai search. Production runs with
the public host; tests override via with_civitai_base.
catalog_intents: Arc<RwLock<HashMap<String, CatalogModelIntent>>>Cache of pure synthesis intents for installed catalog (cv:*/hf:*)
IDs, keyed by ID. Resolution into a ModelConfig is deferred to
engine-load time so disk-state races (file present vs not) can’t
seal a wrong config; see model_manager::resolve_intent_to_paths.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(
engine: Box<dyn InferenceEngine>,
config: Config,
queue: QueueHandle,
gpu_pool: Arc<GpuPool>,
queue_capacity: usize,
) -> Self
pub fn new( engine: Box<dyn InferenceEngine>, config: Config, queue: QueueHandle, gpu_pool: Arc<GpuPool>, queue_capacity: usize, ) -> Self
Create state with a pre-loaded engine (server starts with a configured model).
Sourcepub fn empty(
config: Config,
queue: QueueHandle,
gpu_pool: Arc<GpuPool>,
queue_capacity: usize,
) -> Self
pub fn empty( config: Config, queue: QueueHandle, gpu_pool: Arc<GpuPool>, queue_capacity: usize, ) -> Self
Create state with no engine (zero-config startup, models pulled on demand).
Sourcepub fn for_tests() -> Self
pub fn for_tests() -> Self
Construct an empty AppState for integration tests. Catalog
surfaces hit live HF/Civitai (test callers point those at a
wiremock instance via with_civitai_base).
Sourcepub fn with_civitai_base(self, base: impl Into<String>) -> Self
pub fn with_civitai_base(self, base: impl Into<String>) -> Self
Override the live-search Civitai base URL on an existing state.
Tests point this at a wiremock instance; production never calls
it (the new / empty constructors set the public host).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Freeze for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more