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 <[email protected]>
  • Loading branch information
refi64 authored and sjoerdsimons committed Jan 11, 2024
1 parent 7749b37 commit 73b335b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 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]
[--artifact-expiration ARTIFACT_EXPIRATION='3 days']
[--build-log-out BUILD_LOG_FILE=build.log]
```
Expand Down Expand Up @@ -214,6 +215,12 @@ 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`

Changes the timeout for each generated job, using the [job `timeout`
setting](https://docs.gitlab.com/ee/ci/yaml/#timeout). If not passed, the
timeout will not be set.

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

Changes the expiration of the build results & logs.
Expand Down
15 changes: 13 additions & 2 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct GenerateMonitorAction {
pipeline_out: String,
#[clap(long, default_value_t = DEFAULT_PIPELINE_JOB_PREFIX.to_owned())]
job_prefix: String,
#[clap(long)]
job_timeout: Option<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 +412,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 +1269,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 +1311,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 +1436,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
4 changes: 4 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: Option<String>,
pub rules: Option<String>,
pub build_log_out: String,
pub download_binaries: PipelineDownloadBinaries,
Expand All @@ -35,6 +36,8 @@ struct JobSpec {
before_script: Vec<String>,
script: Vec<String>,
after_script: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
timeout: Option<String>,
artifacts: ArtifactsSpec,
#[serde(skip_serializing_if = "Option::is_none")]
rules: Option<serde_yaml::Sequence>,
Expand Down Expand Up @@ -114,6 +117,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 73b335b

Please sign in to comment.