summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-07-17 13:41:33 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-07-17 13:41:33 +0200
commit254e3448c581344e0b688b847520ff198f60f58b (patch)
treef580f081efe2ab7e8926e1e541ee26e7ee203489 /src
parent07b13fef2d151fbbbfe876051b16a48da6013947 (diff)
downloadrebel-254e3448c581344e0b688b847520ff198f60f58b.tar
rebel-254e3448c581344e0b688b847520ff198f60f58b.zip
executor: save task output in state cache
Diffstat (limited to 'src')
-rw-r--r--src/executor.rs38
-rw-r--r--src/main.rs2
2 files changed, 35 insertions, 5 deletions
diff --git a/src/executor.rs b/src/executor.rs
index 3608696..fea9490 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -1,6 +1,29 @@
-use std::collections::{HashMap, HashSet};
+use std::{
+ collections::{HashMap, HashSet},
+ fs, io,
+ path::{Path, PathBuf},
+};
-use crate::{runner, types::*};
+use crate::{runner, types::*, util::cjson};
+
+fn tmp_filename(hash: &InputHash) -> PathBuf {
+ Path::new("build/state/tmp/task").join(format!("{}.json", hash))
+}
+
+fn task_filename(hash: &InputHash) -> PathBuf {
+ Path::new("build/state/task").join(format!("{}.json", hash))
+}
+
+fn save_output(output: &TaskOutput) -> io::Result<()> {
+ let filename = tmp_filename(&output.input_hash);
+
+ let file = fs::File::create(&filename)?;
+ cjson::to_writer(&file, output)?;
+ file.sync_all()?;
+ drop(file);
+
+ fs::rename(filename, task_filename(&output.input_hash))
+}
#[derive(Debug)]
pub struct Executor<'a> {
@@ -12,7 +35,7 @@ pub struct Executor<'a> {
}
impl<'a> Executor<'a> {
- pub fn new(tasks: &'a TaskMap, taskset: HashSet<TaskID>) -> Self {
+ pub fn new(tasks: &'a TaskMap, taskset: HashSet<TaskID>) -> io::Result<Self> {
let mut exc = Executor {
tasks,
tasks_blocked: HashSet::new(),
@@ -35,7 +58,12 @@ impl<'a> Executor<'a> {
}
}
- exc
+ let mut dir = fs::DirBuilder::new();
+ dir.recursive(true);
+ dir.create("build/state/task")?;
+ dir.create("build/state/tmp/task")?;
+
+ Ok(exc)
}
fn deps_satisfied(&self, task: &TaskID) -> bool {
@@ -83,6 +111,8 @@ impl<'a> Executor<'a> {
output_hash,
};
+ save_output(&output)?;
+
let rdeps = self.rdeps.get(&task.id);
self.tasks_done.insert(task.id, output);
diff --git a/src/main.rs b/src/main.rs
index d3ac7c8..527c2f2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -33,7 +33,7 @@ fn main() {
std::process::exit(1);
}
let taskset = rsv.to_taskset();
- let mut exc = executor::Executor::new(&tasks, taskset);
+ let mut exc = executor::Executor::new(&tasks, taskset).unwrap();
if let Err(error) = exc.run(&runner) {
eprintln!("{}", error);
std::process::exit(1);