Skip to content

Commit

Permalink
Merge pull request #3 from tower/develop
Browse files Browse the repository at this point in the history
Extract Schedule from Towerfile and propagate it to Tower
  • Loading branch information
bradhe authored Jan 22, 2025
2 parents 24a256e + c45c955 commit 6a677bc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/config/src/towerfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ mod test {
assert_eq!(err.to_string(), "Missing required app field `name` in Towerfile");
}

#[ignore]
#[test]
fn test_returns_error_when_missing_local_towerfile() {
// this is a bit of a hack to make sure any local Towerfile is indeed gone. Leaks from
Expand Down
17 changes: 16 additions & 1 deletion crates/tower-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ pub struct Manifest {
pub invoke: String,

#[serde(default)]
pub parameters: Vec<Parameter>
pub parameters: Vec<Parameter>,

// schedule is the schedule that we want to execute this app on. this is, just temporarily,
// where it will live.
pub schedule: Option<String>,
}

impl Manifest {
Expand All @@ -57,6 +61,9 @@ pub struct PackageSpec {

// parameters are the parameters to use for this app.
pub parameters: Vec<Parameter>,

// schedule defines the frequency that this app should be run on.
pub schedule: Option<String>,
}

fn get_parameters(towerfile: &Towerfile) -> Vec<Parameter> {
Expand All @@ -74,8 +81,14 @@ fn get_parameters(towerfile: &Towerfile) -> Vec<Parameter> {
impl PackageSpec {
pub fn from_towerfile(towerfile: &Towerfile) -> Self {
let base_dir = towerfile.base_dir.clone();
let schedule = if towerfile.app.schedule.is_empty() {
None
} else {
Some(towerfile.app.schedule.to_string())
};

Self {
schedule,
base_dir,
invoke: towerfile.app.script.clone(),
file_globs: towerfile.app.source.clone(),
Expand Down Expand Up @@ -108,6 +121,7 @@ impl Package {
version: Some(CURRENT_PACKAGE_VERSION),
invoke: "".to_string(),
parameters: vec![],
schedule: None,
},
}
}
Expand Down Expand Up @@ -172,6 +186,7 @@ impl Package {
version: Some(CURRENT_PACKAGE_VERSION),
invoke: String::from(spec.invoke),
parameters: spec.parameters,
schedule: spec.schedule,
};

// the whole manifest needs to be written to a file as a convenient way to avoid having to
Expand Down
2 changes: 2 additions & 0 deletions crates/tower-package/tests/package_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async fn it_creates_package() {
base_dir: tmp_dir.to_path_buf(),
file_globs: vec!["*.py".to_string()],
parameters: vec![],
schedule: None,
};

let package = Package::build(spec).await.expect("Failed to build package");
Expand Down Expand Up @@ -62,6 +63,7 @@ async fn it_respects_complex_file_globs() {
"**/*.py".to_string(),
],
parameters: vec![],
schedule: None,
};

let package = Package::build(spec).await.expect("Failed to build package");
Expand Down
7 changes: 7 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a677bc

Please sign in to comment.