Skip to content

Commit 73b335b

Browse files
refi64sjoerdsimons
authored andcommitted
Add --job-timeout to generate-runner
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]>
1 parent 7749b37 commit 73b335b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ generate-monitor RUNNER_TAG
133133
[--build-info BUILD_INFO_FILE=build-info.yml]
134134
[--pipeline-out PIPELINE_FILE=obs.yml]
135135
[--job-prefix MONITOR_JOB_PREFIX=obs]
136+
[--job-timeout MONITOR_JOB_TIMEOUT]
136137
[--artifact-expiration ARTIFACT_EXPIRATION='3 days']
137138
[--build-log-out BUILD_LOG_FILE=build.log]
138139
```
@@ -214,6 +215,12 @@ Changes the filename of the child pipeline YAML.
214215
Changes the prefix that will be prepended to each generated job
215216
(`MONITOR_JOB_PREFIX-REPOSITORY-ARCH`).
216217

218+
##### `--job-timeout MONITOR_JOB_TIMEOUT`
219+
220+
Changes the timeout for each generated job, using the [job `timeout`
221+
setting](https://docs.gitlab.com/ee/ci/yaml/#timeout). If not passed, the
222+
timeout will not be set.
223+
217224
##### `--artifact-expiration ARTIFACT_EXPIRATION='3 days'`
218225

219226
Changes the expiration of the build results & logs.

src/handler.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ struct GenerateMonitorAction {
8484
pipeline_out: String,
8585
#[clap(long, default_value_t = DEFAULT_PIPELINE_JOB_PREFIX.to_owned())]
8686
job_prefix: String,
87+
#[clap(long)]
88+
job_timeout: Option<String>,
8789
#[clap(long, default_value_t = DEFAULT_ARTIFACT_EXPIRATION.to_owned())]
8890
artifact_expiration: String,
8991
#[clap(long, default_value_t = DEFAULT_BUILD_LOG.into())]
@@ -410,6 +412,7 @@ impl ObsJobHandler {
410412
tags: vec![args.tag],
411413
artifact_expiration: args.artifact_expiration,
412414
prefix: args.job_prefix,
415+
timeout: args.job_timeout,
413416
rules: args.rules,
414417
download_binaries: if let Some(build_results_dir) = args.build_results_dir {
415418
PipelineDownloadBinaries::OnSuccess {
@@ -1266,6 +1269,7 @@ mod tests {
12661269
download_binaries: bool,
12671270
) {
12681271
const TEST_JOB_RUNNER_TAG: &str = "test-tag";
1272+
const TEST_MONITOR_TIMEOUT: &str = "1 day";
12691273
const TEST_BUILD_RESULTS_DIR: &str = "results";
12701274
const TEST_BUILD_RESULT: &str = "test-build-result";
12711275
const TEST_BUILD_RESULT_CONTENTS: &[u8] = b"abcdef";
@@ -1307,8 +1311,8 @@ mod tests {
13071311
);
13081312

13091313
let mut generate_command = format!(
1310-
"generate-monitor {} --rules '[{{a: 1}}, {{b: 2}}]'",
1311-
TEST_JOB_RUNNER_TAG
1314+
"generate-monitor {} --job-timeout '{}' --rules '[{{a: 1}}, {{b: 2}}]'",
1315+
TEST_JOB_RUNNER_TAG, TEST_MONITOR_TIMEOUT
13121316
);
13131317
if download_binaries {
13141318
generate_command += &format!(" --download-build-results-to {}", TEST_BUILD_RESULTS_DIR);
@@ -1432,6 +1436,13 @@ mod tests {
14321436
assert_eq!(tags.len(), 1);
14331437
assert_eq!(tags[0].as_str().unwrap(), TEST_JOB_RUNNER_TAG);
14341438

1439+
let timeout = monitor_map
1440+
.get(&"timeout".into())
1441+
.unwrap()
1442+
.as_str()
1443+
.unwrap();
1444+
assert_eq!(timeout, TEST_MONITOR_TIMEOUT);
1445+
14351446
let rules: Vec<_> = monitor_map
14361447
.get(&"rules".into())
14371448
.unwrap()

src/pipeline.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct GeneratePipelineOptions {
1717
pub tags: Vec<String>,
1818
pub artifact_expiration: String,
1919
pub prefix: String,
20+
pub timeout: Option<String>,
2021
pub rules: Option<String>,
2122
pub build_log_out: String,
2223
pub download_binaries: PipelineDownloadBinaries,
@@ -35,6 +36,8 @@ struct JobSpec {
3536
before_script: Vec<String>,
3637
script: Vec<String>,
3738
after_script: Vec<String>,
39+
#[serde(skip_serializing_if = "Option::is_none")]
40+
timeout: Option<String>,
3841
artifacts: ArtifactsSpec,
3942
#[serde(skip_serializing_if = "Option::is_none")]
4043
rules: Option<serde_yaml::Sequence>,
@@ -114,6 +117,7 @@ pub fn generate_monitor_pipeline(
114117
// ensure that they're set to be empty.
115118
before_script: vec![],
116119
after_script: vec![],
120+
timeout: options.timeout.clone(),
117121
artifacts: ArtifactsSpec {
118122
paths: artifact_paths,
119123
when: "always".to_owned(),

0 commit comments

Comments
 (0)