Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

A render's sweep keeps the work folder of a render that still runs, however long since its folder changed. The two-hour rule now removes only folders whose process isn't known to run (gone, unknown, or no PID in the name): a render running past two hours stops touching its folder's top level well before it ends, and the next render's sweep deleted it. This render's own folders count as running. pid.rs's test sweeps a folder of aged ones as it would run three hours on. (closes #31)

shinyobjectz5ada16031447
diff --git a/runtime/bundle/src/cache.rs b/runtime/bundle/src/cache.rs
index dc328d4c..1b5fa7c9 100644
--- a/runtime/bundle/src/cache.rs
+++ b/runtime/bundle/src/cache.rs
@@ -234,22 +234,27 @@ impl Drop for Gone {
/// render's pictures run to 14 GB; four killed in eight minutes filled the disk, 10-24), else when nothing has touched
/// them for two hours.
pub fn sweep_stale_work() {
- sweep_stale_work_in(&std::env::temp_dir());
+ sweep_stale_work_in(&std::env::temp_dir(), std::time::SystemTime::now());
}
-pub(crate) fn sweep_stale_work_in(dir: &Path) {
+/// The sweep of DIR as it would run at NOW (a test passes a later NOW to age every folder)
+pub(crate) fn sweep_stale_work_in(dir: &Path, now: std::time::SystemTime) {
let Ok(rd) = std::fs::read_dir(dir) else { return };
- let now = std::time::SystemTime::now();
for e in rd.flatten() {
let name = e.file_name().to_string_lossy().into_owned();
if !["raea-cli-r", "raea-cli-b"].iter().any(|p| name.starts_with(p)) {
continue;
}
let old = e.metadata().and_then(|m| m.modified()).ok().and_then(|t| now.duration_since(t).ok()).is_some_and(|d| d.as_secs() > 2 * 3600);
- // raea-cli-r{pid}-ThreadId(n), raea-cli-b{pid}: gone only when the system says no such process is left
+ // raea-cli-r{pid}-ThreadId(n), raea-cli-b{pid}: gone only when the system says no such process is left, running
+ // when it says it runs (this process's own folders too)
let pid = name.get(10..).and_then(|s| s.split('-').next()).and_then(|p| p.parse::<u32>().ok());
- let gone = pid.is_some_and(|p| p != std::process::id() && crate::pid::running(p) == Some(false));
- if old || gone {
+ let running = pid.map(|p| if p == std::process::id() { Some(true) } else { crate::pid::running(p) });
+ let gone = running == Some(Some(false));
+ // the age rule is for a folder whose process isn't known to run: a long render stops touching its folder's top
+ // level well before it ends (#31), and a killed render's PID handed to another process keeps its folder
+ // until that one ends
+ if gone || (old && running != Some(Some(true))) {
let _ = std::fs::remove_dir_all(e.path());
}
}
diff --git a/runtime/bundle/src/pid.rs b/runtime/bundle/src/pid.rs
index 702d7870..2c18f62d 100644
--- a/runtime/bundle/src/pid.rs
+++ b/runtime/bundle/src/pid.rs
@@ -84,7 +84,7 @@ mod tests {
for n in keep.iter().chain(&go) {
std::fs::create_dir_all(dir.join(n)).unwrap();
}
- crate::cache::sweep_stale_work_in(&dir);
+ crate::cache::sweep_stale_work_in(&dir, std::time::SystemTime::now());
let left: Vec<bool> = keep.iter().chain(&go).map(|n| dir.join(n).exists()).collect();
drop(live.stdin.take());
live.wait().unwrap();
@@ -92,6 +92,35 @@ mod tests {
assert_eq!(left, [true, true, true, false, false], "kept: {keep:?}, removed: {go:?}");
}
+ /// Two hours untouched removes a folder only when its render isn't known to run: a long render stops touching its
+ /// folder's top level well before it ends (#31)
+ #[test]
+ fn the_age_rule_spares_a_running_render() {
+ let dir = std::env::temp_dir().join(format!("raea-pid-age-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ let mut live = child();
+ let mut ended = child();
+ drop(ended.stdin.take());
+ ended.wait().unwrap();
+ let names = [
+ format!("raea-cli-b{}", live.id()),
+ format!("raea-cli-r{}-ThreadId(2)", std::process::id()),
+ format!("raea-cli-b{}", ended.id()),
+ "raea-cli-bx".to_string(),
+ ];
+ for n in &names {
+ std::fs::create_dir_all(dir.join(n)).unwrap();
+ }
+ // three hours from now, every folder is two hours untouched
+ crate::cache::sweep_stale_work_in(&dir, std::time::SystemTime::now() + std::time::Duration::from_secs(3 * 3600));
+ let left: Vec<bool> = names.iter().map(|n| dir.join(n).exists()).collect();
+ drop(live.stdin.take());
+ live.wait().unwrap();
+ let _ = std::fs::remove_dir_all(&dir);
+ // a running render's (another process's, and this one's) stay; an ended one's and one naming no process go
+ assert_eq!(left, [true, true, false, false], "{names:?}");
+ }
+
#[test]
fn a_pid_naming_no_one_process_is_unknown_or_gone() {
// 0 and pids past i32::MAX are groups to kill(2), never "running"