Skip to main content

lumen_server/service/
types.rs

1use std::{collections::HashMap, future::Future, path::PathBuf, pin::Pin, time::Instant};
2
3use serde_json::Value;
4
5pub type ServiceResult<T> = Result<T, ServiceError>;
6pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
7
8#[derive(Debug, Clone)]
9pub struct RenderJob {
10    pub id: RenderJobId,
11    pub project: Value,
12    pub media_root: Option<PathBuf>,
13    pub video_encoder: Option<String>,
14    pub metadata: HashMap<String, String>,
15}
16
17impl RenderJob {
18    pub fn new(id: impl Into<String>, project: Value) -> Self {
19        Self {
20            id: RenderJobId(id.into()),
21            project,
22            media_root: None,
23            video_encoder: None,
24            metadata: HashMap::new(),
25        }
26    }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Hash)]
30pub struct RenderJobId(pub String);
31
32#[derive(Debug, Clone, PartialEq, Eq, Hash)]
33pub struct RenderLeaseId(pub String);
34
35#[derive(Debug, Clone)]
36pub struct RenderLease {
37    pub id: RenderLeaseId,
38    pub job: RenderJob,
39    pub leased_until: Instant,
40}
41
42#[derive(Debug, Clone)]
43pub struct WorkerId(pub String);
44
45#[derive(Debug, Clone)]
46pub struct RenderOutput {
47    pub bytes: Vec<u8>,
48    pub content_type: &'static str,
49    pub metrics: RenderMetrics,
50}
51
52#[derive(Debug, Clone)]
53pub struct RenderMetrics {
54    pub render_ms: u128,
55    pub total_frames: u64,
56}
57
58#[derive(Debug, Clone)]
59pub struct ArtifactWrite {
60    pub job_id: RenderJobId,
61    pub bytes: Vec<u8>,
62    pub content_type: &'static str,
63}
64
65#[derive(Debug, Clone)]
66pub struct ArtifactRef {
67    pub id: String,
68    pub content_type: &'static str,
69    pub bytes: usize,
70    pub uri: String,
71}
72
73#[derive(Debug, Clone)]
74pub struct ProgressEvent {
75    pub job_id: RenderJobId,
76    pub stage: String,
77    pub ratio: f32,
78    pub frame: Option<u32>,
79    pub total_frames: Option<u32>,
80}
81
82#[derive(Debug, Clone)]
83pub struct ServiceError {
84    pub code: &'static str,
85    pub message: String,
86    pub retryable: bool,
87}
88
89impl std::fmt::Display for ServiceError {
90    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91        write!(f, "{}: {}", self.code, self.message)
92    }
93}
94
95impl std::error::Error for ServiceError {}
96
97impl From<crate::render::RenderError> for ServiceError {
98    fn from(error: crate::render::RenderError) -> Self {
99        Self {
100            code: error.code,
101            message: error.message,
102            retryable: error.retryable,
103        }
104    }
105}