pub struct DraftStore { /* private fields */ }Expand description
Filesystem-backed draft surface.
Implementations§
Source§impl DraftStore
impl DraftStore
Sourcepub fn state_dir(&self, state: DraftState) -> PathBuf
pub fn state_dir(&self, state: DraftState) -> PathBuf
Directory for a lifecycle state.
Sourcepub fn path_for(&self, state: DraftState, id: DraftId) -> PathBuf
pub fn path_for(&self, state: DraftState, id: DraftId) -> PathBuf
Canonical path for a draft in a lifecycle state.
Sourcepub fn ensure_dirs(&self) -> Result<(), LibrarianError>
pub fn ensure_dirs(&self) -> Result<(), LibrarianError>
Ensure all lifecycle directories exist.
§Errors
Returns LibrarianError::DraftIo when a lifecycle directory
cannot be created.
Sourcepub fn submit(&self, draft: &Draft) -> Result<PathBuf, LibrarianError>
pub fn submit(&self, draft: &Draft) -> Result<PathBuf, LibrarianError>
Submit a draft into pending/ as a v2 JSON envelope.
If the target file already exists, submission is treated as idempotent and the existing path is returned.
§Errors
Returns LibrarianError::DraftIo if the directory or file
operations fail, or LibrarianError::DraftJson if the draft
envelope cannot be encoded.
Sourcepub fn load(
&self,
state: DraftState,
id: DraftId,
) -> Result<Draft, LibrarianError>
pub fn load( &self, state: DraftState, id: DraftId, ) -> Result<Draft, LibrarianError>
Load one draft from a state directory.
§Errors
Returns LibrarianError::DraftIo if the file cannot be read,
LibrarianError::DraftJson if it is not valid JSON,
LibrarianError::UnsupportedDraftSchema for unknown schema
versions, or LibrarianError::DraftIdMismatch if the stored
ID does not match the envelope.
Sourcepub fn list(&self, state: DraftState) -> Result<Vec<Draft>, LibrarianError>
pub fn list(&self, state: DraftState) -> Result<Vec<Draft>, LibrarianError>
List drafts in one state directory.
§Errors
Returns the same errors as DraftStore::load for any listed
draft, and LibrarianError::DraftIo if the state directory
cannot be read.
Sourcepub fn transition(
&self,
id: DraftId,
from: DraftState,
to: DraftState,
) -> Result<DraftTransition, LibrarianError>
pub fn transition( &self, id: DraftId, from: DraftState, to: DraftState, ) -> Result<DraftTransition, LibrarianError>
Move a draft from one lifecycle state to another.
The state graph is intentionally small:
pending -> processingclaims work for a run.processing -> accepted | skipped | failed | quarantinedfinishes work.processing -> pendingrecovers stale in-flight work after a crash or abandoned run.
The file move is a single filesystem rename. The method refuses to overwrite an existing target path.
§Errors
Returns LibrarianError::InvalidDraftTransition for edges
outside the lifecycle graph, LibrarianError::DraftNotFound
when the source file is absent, LibrarianError::DraftAlreadyExists
when the target path is already occupied, or the same load / I/O
errors as DraftStore::load.
Sourcepub fn recover_stale_processing(
&self,
stale_before: SystemTime,
) -> Result<Vec<DraftTransition>, LibrarianError>
pub fn recover_stale_processing( &self, stale_before: SystemTime, ) -> Result<Vec<DraftTransition>, LibrarianError>
Recover stale drafts from processing/ back to pending/.
A processing draft is stale when its claim marker modified time
is at or before stale_before. Callers usually pass
SystemTime::now() - processing_timeout; tests can pass a future
cutoff to recover all processing drafts deterministically.
§Errors
Returns the same errors as DraftStore::transition for any
stale draft that cannot be moved, plus LibrarianError::DraftIo
for directory iteration or metadata errors.
Trait Implementations§
Source§impl Clone for DraftStore
impl Clone for DraftStore
Source§fn clone(&self) -> DraftStore
fn clone(&self) -> DraftStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more