core/types: make results explicit for cleanup()
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5795e5c6eb10d9a869d3cc88f2fdbb926a6a6964
This commit is contained in:
parent
a397426858
commit
c71c576c29
1 changed files with 24 additions and 4 deletions
|
|
@ -4,9 +4,11 @@ use chrono::{DateTime, Utc};
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[must_use]
|
||||
pub struct ContentHash(pub String);
|
||||
|
||||
impl ContentHash {
|
||||
/// Creates a new content hash.
|
||||
pub fn new(hash: impl Into<String>) -> Self {
|
||||
Self(hash.into())
|
||||
}
|
||||
|
|
@ -19,6 +21,7 @@ impl AsRef<str> for ContentHash {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[must_use]
|
||||
pub struct JobId(pub uuid::Uuid);
|
||||
|
||||
impl JobId {
|
||||
|
|
@ -34,6 +37,7 @@ impl Default for JobId {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[must_use]
|
||||
pub struct RunId(pub uuid::Uuid);
|
||||
|
||||
impl RunId {
|
||||
|
|
@ -50,6 +54,7 @@ impl Default for RunId {
|
|||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[must_use]
|
||||
pub enum JobStatus {
|
||||
Discovered,
|
||||
Fetching,
|
||||
|
|
@ -60,6 +65,7 @@ pub enum JobStatus {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[must_use]
|
||||
pub struct SourceProvenance {
|
||||
pub source_id: String,
|
||||
pub entity_type: EntityType,
|
||||
|
|
@ -69,6 +75,7 @@ pub struct SourceProvenance {
|
|||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[must_use]
|
||||
pub enum EntityType {
|
||||
Repository,
|
||||
Wiki,
|
||||
|
|
@ -89,6 +96,7 @@ pub struct Artifact {
|
|||
}
|
||||
|
||||
impl Artifact {
|
||||
#[must_use]
|
||||
pub const fn new(
|
||||
content_hash: ContentHash,
|
||||
size_bytes: u64,
|
||||
|
|
@ -103,18 +111,27 @@ impl Artifact {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the path to the temporary file.
|
||||
#[must_use]
|
||||
pub fn temp_path(&self) -> &std::path::Path {
|
||||
&self.temp_path
|
||||
}
|
||||
|
||||
/// Explicitly clean up the temporary file.
|
||||
/// This should be called after all sinks have processed the artifact.
|
||||
pub async fn cleanup(&self) {
|
||||
let _ = tokio::fs::remove_file(&self.temp_path).await;
|
||||
/// Explicitly clean up the temporary file. This should be called after all
|
||||
/// sinks have processed the artifact.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the file cannot be removed (e.g., permissions,
|
||||
/// file not found, or IO errors).
|
||||
pub async fn cleanup(&self) -> anyhow::Result<()> {
|
||||
tokio::fs::remove_file(&self.temp_path).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[must_use]
|
||||
pub struct SinkJobState {
|
||||
pub status: JobStatus,
|
||||
pub receipt: Option<StorageReceipt>,
|
||||
|
|
@ -122,6 +139,7 @@ pub struct SinkJobState {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[must_use]
|
||||
pub struct StorageReceipt {
|
||||
pub sink_id: String,
|
||||
pub uri: String,
|
||||
|
|
@ -129,6 +147,7 @@ pub struct StorageReceipt {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[must_use]
|
||||
pub struct ManifestEntry {
|
||||
pub hash: ContentHash,
|
||||
pub size: u64,
|
||||
|
|
@ -149,6 +168,7 @@ pub struct Job {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[must_use]
|
||||
pub struct Manifest {
|
||||
pub run_id: RunId,
|
||||
pub created_at: DateTime<Utc>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue