1use std::path::PathBuf;
3use std::sync::Arc; use serde::{Deserialize, Serialize};
6
7use crate::dependency::ResolvedGraph; use crate::error::SpsError;
9use crate::model::InstallTargetIdentifier;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
14pub enum PipelinePackageType {
15 Formula,
16 Cask,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub enum JobAction {
21 Install,
22 Upgrade {
23 from_version: String,
24 old_install_path: PathBuf,
25 },
26 Reinstall {
27 version: String,
28 current_install_path: PathBuf,
29 },
30}
31
32#[derive(Debug, Clone)]
33pub struct PlannedJob {
34 pub target_id: String,
35 pub target_definition: InstallTargetIdentifier,
36 pub action: JobAction,
37 pub is_source_build: bool,
38 pub use_private_store_source: Option<PathBuf>,
39}
40
41#[derive(Debug, Clone)]
42pub struct WorkerJob {
43 pub request: PlannedJob,
44 pub download_path: PathBuf,
45 pub download_size_bytes: u64,
46 pub is_source_from_private_store: bool,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub enum PipelineEvent {
51 PipelineStarted {
52 total_jobs: usize,
53 },
54 PipelineFinished {
55 duration_secs: f64,
56 success_count: usize,
57 fail_count: usize,
58 },
59 PlanningStarted,
60 DependencyResolutionStarted,
61 DependencyResolutionFinished,
62 PlanningFinished {
63 job_count: usize,
64 },
68 DownloadStarted {
69 target_id: String,
70 url: String,
71 },
72 DownloadFinished {
73 target_id: String,
74 path: PathBuf,
75 size_bytes: u64,
76 },
77 DownloadFailed {
78 target_id: String,
79 url: String,
80 error: String, },
82 JobProcessingStarted {
83 target_id: String,
85 },
86 JobDispatchedToCore {
87 target_id: String,
89 },
90 UninstallStarted {
91 target_id: String,
92 version: String,
93 },
94 UninstallFinished {
95 target_id: String,
96 version: String,
97 },
98 BuildStarted {
99 target_id: String,
100 },
101 InstallStarted {
102 target_id: String,
103 pkg_type: PipelinePackageType,
104 },
105 LinkStarted {
106 target_id: String,
107 pkg_type: PipelinePackageType,
108 },
109 JobSuccess {
110 target_id: String,
112 action: JobAction,
113 pkg_type: PipelinePackageType,
114 },
115 JobFailed {
116 target_id: String,
118 action: JobAction, error: String, },
121 LogInfo {
122 message: String,
123 },
124 LogWarn {
125 message: String,
126 },
127 LogError {
128 message: String,
129 },
130}
131
132impl PipelineEvent {
133 pub fn job_failed(target_id: String, action: JobAction, error: &SpsError) -> Self {
135 PipelineEvent::JobFailed {
136 target_id,
137 action,
138 error: error.to_string(),
139 }
140 }
141 pub fn download_failed(target_id: String, url: String, error: &SpsError) -> Self {
142 PipelineEvent::DownloadFailed {
143 target_id,
144 url,
145 error: error.to_string(),
146 }
147 }
148}
149
150#[derive(Debug, Clone)]
154pub enum JobProcessingState {
155 PendingDownload,
157 Downloading,
159 Downloaded(PathBuf),
161 WaitingForDependencies(PathBuf),
163 DispatchedToCore(PathBuf),
165 Installing(PathBuf), Succeeded,
169 Failed(Arc<SpsError>),
171}
172
173#[derive(Debug)] pub struct DownloadOutcome {
176 pub planned_job: PlannedJob, pub result: Result<PathBuf, SpsError>, }
179
180#[derive(Debug, Default)]
182pub struct PlannedOperations {
183 pub jobs: Vec<PlannedJob>, pub errors: Vec<(String, SpsError)>, pub already_installed_or_up_to_date: std::collections::HashSet<String>,
186 pub resolved_graph: Option<Arc<ResolvedGraph>>, }