Skip to content

Commit

Permalink
Add output_path field to Task::Options struct
Browse files Browse the repository at this point in the history
This commit adds `output_path` field to `Task::Options` struct. This
is needed to partially address request golemfactory/g-flite#28. The
field is made optional, and serialized only if is not `None`.
  • Loading branch information
Jakub Konka authored and kubkon committed Oct 31, 2019
1 parent e16dcda commit dd071b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gwasm-api"
version = "0.1.1"
version = "0.1.2"
authors = ["Golem RnD Team <[email protected]>"]
edition = "2018"
license = "GPL-3.0"
Expand Down
20 changes: 20 additions & 0 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct TaskBuilder<'a> {
subtask_timeout: Option<Timeout>,
input_dir_path: PathBuf,
output_dir_path: PathBuf,
output_path: Option<PathBuf>,
subtask_data: Vec<Vec<u8>>,
}

Expand All @@ -69,6 +70,7 @@ impl<'a> TaskBuilder<'a> {
subtask_timeout: None,
input_dir_path: workspace.as_ref().join("in"),
output_dir_path: workspace.as_ref().join("out"),
output_path: None,
subtask_data: Vec::new(),
}
}
Expand Down Expand Up @@ -97,6 +99,13 @@ impl<'a> TaskBuilder<'a> {
self
}

/// Sets task's expected output path, i.e., where the final result of
/// the task is meant to land
pub fn output_path<P: AsRef<Path>>(mut self, output_path: P) -> Self {
self.output_path = Some(output_path.as_ref().into());
self
}

/// Pushes subtask data into the buffer
///
/// Note that each pushed chunk of `data` is equivalent to one
Expand Down Expand Up @@ -132,6 +141,7 @@ impl<'a> TaskBuilder<'a> {
wasm_name,
self.input_dir_path.clone(),
self.output_dir_path.clone(),
self.output_path.clone(),
);

// create input dir
Expand Down Expand Up @@ -274,6 +284,8 @@ pub struct Options {
input_dir_path: PathBuf,
#[serde(rename = "output_dir")]
output_dir_path: PathBuf,
#[serde(skip_serializing_if = "Option::is_none")]
output_path: Option<PathBuf>,
subtasks: BTreeMap<String, Subtask>,
}

Expand All @@ -284,12 +296,14 @@ impl Options {
wasm_name: S,
input_dir_path: P,
output_dir_path: P,
output_path: Option<P>,
) -> Self {
Self {
js_name: js_name.into(),
wasm_name: wasm_name.into(),
input_dir_path: input_dir_path.into(),
output_dir_path: output_dir_path.into(),
output_path: output_path.map(Into::into),
subtasks: BTreeMap::new(),
}
}
Expand All @@ -314,6 +328,12 @@ impl Options {
&self.output_dir_path
}

/// Path to the dir where the final output of the task
/// is expected
pub fn output_path(&self) -> Option<&Path> {
self.output_path.as_ref().map(AsRef::as_ref)
}

/// Returns an [`Iterator`] over created [`Subtask`]'s
///
/// [`Subtask`]: ../task/struct.Subtask.html
Expand Down

0 comments on commit dd071b9

Please sign in to comment.