Skip to main content

AppState

Struct AppState 

Source
pub struct AppState {
Show 22 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 queue: QueueHandle, pub job_registry: SharedJobRegistry, pub queue_pause: Arc<QueuePause>, 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 chain_jobs: Option<Arc<ChainJobRunnerHandle>>, pub downloads: Arc<DownloadQueue>, pub resources: Arc<ResourceBroadcaster>, pub events: Arc<EventBroadcaster>, 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: usize

Maximum 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.

§queue: QueueHandle

Generation request queue.

§job_registry: SharedJobRegistry

Authoritative 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.

§queue_pause: Arc<QueuePause>

Dispatch pause gate toggled by POST /api/queue/pause / POST /api/queue/resume. The dispatch loops park on this at the top of each iteration; a job already running on a worker finishes untouched.

§shared_pool: Arc<Mutex<SharedPool>>

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.

§chain_jobs: Option<Arc<ChainJobRunnerHandle>>

Durable chain-job runner handle. None when DB-backed chain jobs are unavailable; chain-job API handlers return 503 in that state.

§downloads: Arc<DownloadQueue>

Bounded-parallel download queue.

§resources: Arc<ResourceBroadcaster>

Always-on resource telemetry (Agent B).

§events: Arc<EventBroadcaster>

Server-wide lifecycle broadcast backing GET /api/events — job queued/started/ended (mirrored by job_registry) plus gallery added/removed. One SSE connection observes the whole server.

§catalog_live_cache: LiveCache

In-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

Source

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).

Source

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).

Source

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).

Source

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§

Source§

impl Clone for AppState

Source§

fn clone(&self) -> AppState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more