Skip to content

Commit

Permalink
monitor: move per-runner data to data/runners
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Jan 1, 2025
1 parent 4e24281 commit 1f1d400
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion create-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ register_runner=$script_dir/$configuration_name/register-runner.sh
vm=$base_vm.$id
>&2 printf '[*] Creating runner: %s\n' $vm

runner_data=$SERVO_CI_MONITOR_DATA_PATH/$id
runner_data=$SERVO_CI_MONITOR_DATA_PATH/runners/$id
mkdir $runner_data
touch $runner_data/created-time

Expand Down
40 changes: 38 additions & 2 deletions monitor/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{
fs,
fs::{self, create_dir_all, read_dir, rename, File},
path::{Path, PathBuf},
};

use jane_eyre::eyre;
use tracing::info;

use crate::DOTENV;

Expand All @@ -20,7 +21,42 @@ pub fn get_data_path(path: impl AsRef<Path>) -> eyre::Result<PathBuf> {
}

pub fn get_runner_data_path(id: usize, path: impl AsRef<Path>) -> eyre::Result<PathBuf> {
let runner_data = get_data_path(id.to_string())?;
let runner_data = get_data_path("runners")?.join(id.to_string());

Ok(runner_data.join(path))
}

#[tracing::instrument]
pub fn run_migrations() -> eyre::Result<()> {
let migrations_dir = get_data_path("migrations")?;
create_dir_all(&migrations_dir)?;

for version in 1.. {
let marker_path = migrations_dir.join(version.to_string());
if marker_path.try_exists()? {
continue;
}
match version {
1 => {
info!("Moving per-runner data to runners subdirectory");
let runners_dir = get_data_path("runners")?;
create_dir_all(&runners_dir)?;
for entry in read_dir(get_data_path(".")?)? {
let entry = entry?;
// Move entries that parse as a runner id (usize)
if entry
.file_name()
.to_str()
.is_some_and(|n| n.parse::<usize>().is_ok())
{
rename(entry.path(), runners_dir.join(entry.file_name()))?;
}
}
}
_ => break,
}
File::create(marker_path)?;
}

Ok(())
}
4 changes: 3 additions & 1 deletion monitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use warp::{

use crate::{
dashboard::Dashboard,
data::get_runner_data_path,
data::{get_runner_data_path, run_migrations},
github::{list_registered_runners_for_host, Cache},
id::IdGen,
libvirt::list_runner_guests,
Expand Down Expand Up @@ -126,6 +126,8 @@ async fn main() -> eyre::Result<()> {
.with(EnvFilter::builder().from_env_lossy())
.init();

run_migrations()?;

tokio::task::spawn(async move {
let thread = thread::spawn(monitor_thread);
loop {
Expand Down

0 comments on commit 1f1d400

Please sign in to comment.