Skip to content

Commit

Permalink
Add --job-timeout to generate-runner
Browse files Browse the repository at this point in the history
This will allow the user to set the exact timeout to use for the
generated monitor jobs, which is useful if they're known to take a long
time.

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
  • Loading branch information
refi64 committed Jan 10, 2024
1 parent 1c74528 commit d28773c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ generate-monitor RUNNER_TAG
[--build-info BUILD_INFO_FILE=build-info.yml]
[--pipeline-out PIPELINE_FILE=obs.yml]
[--job-prefix MONITOR_JOB_PREFIX=obs]
[--job-timeout MONITOR_JOB_TIMEOUT='1 hour']
[--artifact-expiration ARTIFACT_EXPIRATION='3 days']
[--build-log-out BUILD_LOG_FILE=build.log]
```
Expand Down Expand Up @@ -214,6 +215,10 @@ Changes the filename of the child pipeline YAML.
Changes the prefix that will be prepended to each generated job
(`MONITOR_JOB_PREFIX-REPOSITORY-ARCH`).

##### `--job-timeout MONITOR_JOB_TIMEOUT='1 hour'`

Changes the timeout for each generated job.

##### `--artifact-expiration ARTIFACT_EXPIRATION='3 days'`

Changes the expiration of the build results & logs.
Expand Down
16 changes: 14 additions & 2 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::{
const DEFAULT_BUILD_INFO: &str = "build-info.yml";
const DEFAULT_MONITOR_PIPELINE: &str = "obs.yml";
const DEFAULT_PIPELINE_JOB_PREFIX: &str = "obs";
const DEFAULT_PIPELINE_JOB_TIMEOUT: &str = "1 hour";
const DEFAULT_ARTIFACT_EXPIRATION: &str = "3 days";
const DEFAULT_BUILD_LOG: &str = "build.log";

Expand Down Expand Up @@ -84,6 +85,8 @@ struct GenerateMonitorAction {
pipeline_out: String,
#[clap(long, default_value_t = DEFAULT_PIPELINE_JOB_PREFIX.to_owned())]
job_prefix: String,
#[clap(long, default_value_t = DEFAULT_PIPELINE_JOB_TIMEOUT.to_owned())]
job_timeout: String,
#[clap(long, default_value_t = DEFAULT_ARTIFACT_EXPIRATION.to_owned())]
artifact_expiration: String,
#[clap(long, default_value_t = DEFAULT_BUILD_LOG.into())]
Expand Down Expand Up @@ -410,6 +413,7 @@ impl ObsJobHandler {
tags: vec![args.tag],
artifact_expiration: args.artifact_expiration,
prefix: args.job_prefix,
timeout: args.job_timeout,
rules: args.rules,
download_binaries: if let Some(build_results_dir) = args.build_results_dir {
PipelineDownloadBinaries::OnSuccess {
Expand Down Expand Up @@ -1266,6 +1270,7 @@ mod tests {
download_binaries: bool,
) {
const TEST_JOB_RUNNER_TAG: &str = "test-tag";
const TEST_MONITOR_TIMEOUT: &str = "1 day";
const TEST_BUILD_RESULTS_DIR: &str = "results";
const TEST_BUILD_RESULT: &str = "test-build-result";
const TEST_BUILD_RESULT_CONTENTS: &[u8] = b"abcdef";
Expand Down Expand Up @@ -1307,8 +1312,8 @@ mod tests {
);

let mut generate_command = format!(
"generate-monitor {} --rules '[{{a: 1}}, {{b: 2}}]'",
TEST_JOB_RUNNER_TAG
"generate-monitor {} --job-timeout '{}' --rules '[{{a: 1}}, {{b: 2}}]'",
TEST_JOB_RUNNER_TAG, TEST_MONITOR_TIMEOUT
);
if download_binaries {
generate_command += &format!(" --download-build-results-to {}", TEST_BUILD_RESULTS_DIR);
Expand Down Expand Up @@ -1432,6 +1437,13 @@ mod tests {
assert_eq!(tags.len(), 1);
assert_eq!(tags[0].as_str().unwrap(), TEST_JOB_RUNNER_TAG);

let timeout = monitor_map
.get(&"timeout".into())
.unwrap()
.as_str()
.unwrap();
assert_eq!(timeout, TEST_MONITOR_TIMEOUT);

let rules: Vec<_> = monitor_map
.get(&"rules".into())
.unwrap()
Expand Down
3 changes: 3 additions & 0 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct GeneratePipelineOptions {
pub tags: Vec<String>,
pub artifact_expiration: String,
pub prefix: String,
pub timeout: String,
pub rules: Option<String>,
pub build_log_out: String,
pub download_binaries: PipelineDownloadBinaries,
Expand All @@ -35,6 +36,7 @@ struct JobSpec {
before_script: Vec<String>,
script: Vec<String>,
after_script: Vec<String>,
timeout: String,
artifacts: ArtifactsSpec,
#[serde(skip_serializing_if = "Option::is_none")]
rules: Option<serde_yaml::Sequence>,
Expand Down Expand Up @@ -114,6 +116,7 @@ pub fn generate_monitor_pipeline(
// ensure that they're set to be empty.
before_script: vec![],
after_script: vec![],
timeout: options.timeout.clone(),
artifacts: ArtifactsSpec {
paths: artifact_paths,
when: "always".to_owned(),
Expand Down

0 comments on commit d28773c

Please sign in to comment.