Skip to content

Commit 6ad78c6

Browse files
committed
monitor: update screenshots for profile guests (#6)
1 parent 00da160 commit 6ad78c6

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

monitor/src/data.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ pub fn get_runner_data_path(id: usize, path: impl AsRef<Path>) -> eyre::Result<P
2626
Ok(runner_data.join(path))
2727
}
2828

29+
pub fn get_profile_data_path(key: &str, path: impl AsRef<Path>) -> eyre::Result<PathBuf> {
30+
let profile_data = get_data_path("profiles")?.join(key);
31+
32+
Ok(profile_data.join(path))
33+
}
34+
2935
#[tracing::instrument]
3036
pub fn run_migrations() -> eyre::Result<()> {
3137
let migrations_dir = get_data_path("migrations")?;

monitor/src/libvirt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::str;
22
use std::{
3-
fs::rename,
3+
fs::{create_dir_all, rename},
44
path::Path,
55
process::{Command, Stdio},
66
};
@@ -36,6 +36,7 @@ pub fn libvirt_prefix() -> String {
3636
}
3737

3838
pub fn update_screenshot(guest_name: &str, output_dir: &Path) -> Result<(), eyre::Error> {
39+
create_dir_all(output_dir)?;
3940
let new_path = output_dir.join("screenshot.png.new");
4041
let exit_status = SHELL
4142
.lock()

monitor/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ fn monitor_thread() -> eyre::Result<()> {
468468
if let Ok(mut dashboard) = DASHBOARD.write() {
469469
*dashboard = Some(Dashboard::render(&profile_runner_counts, &runners)?);
470470
runners.update_screenshots();
471+
for (_key, profile) in TOML.profiles() {
472+
profile.update_screenshot();
473+
}
471474
}
472475

473476
// Handle one request from the API.

monitor/src/profile.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use std::process::Command;
22

33
use jane_eyre::eyre;
44
use serde::{Deserialize, Serialize};
5-
use tracing::info;
5+
use tracing::{debug, info};
66

77
use crate::{
8+
data::get_profile_data_path,
9+
libvirt::update_screenshot,
810
runner::{Runner, Runners, Status},
911
DOTENV,
1012
};
@@ -163,4 +165,21 @@ impl Profile {
163165
0
164166
}
165167
}
168+
169+
pub fn update_screenshot(&self) {
170+
if let Err(error) = self.try_update_screenshot() {
171+
debug!(
172+
self.base_vm_name,
173+
?error,
174+
"Failed to update screenshot for profile guest"
175+
);
176+
}
177+
}
178+
179+
fn try_update_screenshot(&self) -> eyre::Result<()> {
180+
let output_dir = get_profile_data_path(&self.base_vm_name, ".")?;
181+
update_screenshot(&self.base_vm_name, &output_dir)?;
182+
183+
Ok(())
184+
}
166185
}

0 commit comments

Comments
 (0)