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 DownloadProgressUpdate {
78 target_id: String,
79 bytes_so_far: u64,
80 total_size: Option<u64>,
81 },
82 DownloadCached {
83 target_id: String,
84 size_bytes: u64,
85 },
86 DownloadFailed {
87 target_id: String,
88 url: String,
89 error: String, },
91 JobProcessingStarted {
92 target_id: String,
94 },
95 JobDispatchedToCore {
96 target_id: String,
98 },
99 UninstallStarted {
100 target_id: String,
101 version: String,
102 },
103 UninstallFinished {
104 target_id: String,
105 version: String,
106 },
107 BuildStarted {
108 target_id: String,
109 },
110 InstallStarted {
111 target_id: String,
112 pkg_type: PipelinePackageType,
113 },
114 LinkStarted {
115 target_id: String,
116 pkg_type: PipelinePackageType,
117 },
118 JobSuccess {
119 target_id: String,
121 action: JobAction,
122 pkg_type: PipelinePackageType,
123 },
124 JobFailed {
125 target_id: String,
127 action: JobAction, error: String, },
130 LogInfo {
131 message: String,
132 },
133 LogWarn {
134 message: String,
135 },
136 LogError {
137 message: String,
138 },
139}
140
141impl PipelineEvent {
142 pub fn job_failed(target_id: String, action: JobAction, error: &SpsError) -> Self {
144 PipelineEvent::JobFailed {
145 target_id,
146 action,
147 error: error.to_string(),
148 }
149 }
150 pub fn download_failed(target_id: String, url: String, error: &SpsError) -> Self {
151 PipelineEvent::DownloadFailed {
152 target_id,
153 url,
154 error: error.to_string(),
155 }
156 }
157}
158
159#[derive(Debug, Clone)]
163pub enum JobProcessingState {
164 PendingDownload,
166 Downloading,
168 Downloaded(PathBuf),
170 WaitingForDependencies(PathBuf),
172 DispatchedToCore(PathBuf),
174 Installing(PathBuf), Succeeded,
178 Failed(Arc<SpsError>),
180}
181
182#[derive(Debug)] pub struct DownloadOutcome {
185 pub planned_job: PlannedJob, pub result: Result<PathBuf, SpsError>, }
188
189#[derive(Debug, Default)]
191pub struct PlannedOperations {
192 pub jobs: Vec<PlannedJob>, pub errors: Vec<(String, SpsError)>, pub already_installed_or_up_to_date: std::collections::HashSet<String>,
195 pub resolved_graph: Option<Arc<ResolvedGraph>>, }