(
context: &JobContext,
str: String,
count: u32,
total: u32,
cancel: &Receiver<()>,
)
| 200 | } |
| 201 | |
| 202 | fn update_status( |
| 203 | context: &JobContext, |
| 204 | str: String, |
| 205 | count: u32, |
| 206 | total: u32, |
| 207 | cancel: &Receiver<()>, |
| 208 | ) -> Result<()> { |
| 209 | let mut w = |
| 210 | context.status.write().map_err(|_| anyhow::Error::msg("Failed to lock job status"))?; |
| 211 | w.progress_items = Some([count, total]); |
| 212 | w.progress_percent = count as f32 / total as f32; |
| 213 | if should_cancel(cancel) { |
| 214 | w.status = "Cancelled".to_string(); |
| 215 | return Err(anyhow::Error::msg("Cancelled")); |
| 216 | } else { |
| 217 | w.status = str; |
| 218 | } |
| 219 | drop(w); |
| 220 | context.waker.wake_by_ref(); |
| 221 | Ok(()) |
| 222 | } |
| 223 | |
| 224 | fn should_cancel(rx: &Receiver<()>) -> bool { |
| 225 | match rx.try_recv() { |
no test coverage detected