Skip to main content

qualia_core_db/q42/asset_import/
status.rs

1//! Import job status and promote result.
2
3use super::error::ImportError;
4use std::path::PathBuf;
5
6/// Lifecycle status for a bounded import job.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum ImportStatus {
9    Running,
10    Cancelled,
11    Failed(String),
12    Succeeded {
13        bytes_read: u64,
14        accepted: u64,
15        quarantined: u64,
16        output_bytes: u64,
17    },
18}
19
20impl ImportStatus {
21    /// `true` when `succeeded`.
22    pub fn is_succeeded(&self) -> bool {
23        matches!(self, Self::Succeeded { .. })
24    }
25}
26
27/// Progress returned by one `feed_chunk` call.
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub struct FeedProgress {
30    /// Bytes consumed from the immutable raw scratch copy in this call.
31    pub bytes_this_chunk: u64,
32    /// Cumulative bytes read from raw so far.
33    pub bytes_read_total: u64,
34    /// True when the raw stream is exhausted after this call.
35    pub eof: bool,
36}
37
38/// Per-chunk accept / quarantine counts from the caller callback.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
40pub struct ChunkOutcome {
41    pub accepted: u64,
42    pub quarantined: u64,
43}
44
45/// Artifact moved out of scratch on successful promote.
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct PromotedArtifact {
48    pub path: PathBuf,
49    pub sha256: [u8; 32],
50    pub bytes: u64,
51    pub accepted: u64,
52    pub quarantined: u64,
53}
54
55impl ImportStatus {
56    /// `Ok(())` iff the import succeeded.
57    pub(crate) fn require_succeeded(&self) -> Result<(u64, u64, u64, u64), ImportError> {
58        match self {
59            Self::Succeeded {
60                bytes_read,
61                accepted,
62                quarantined,
63                output_bytes,
64            } => Ok((*bytes_read, *accepted, *quarantined, *output_bytes)),
65            Self::Cancelled => Err(ImportError::Cancelled),
66            _ => Err(ImportError::NotSucceeded),
67        }
68    }
69}