Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
fix: parse "concurrent_adapters" in config correctly
Lars Wirzenius committed 11 months ago
commit b93695ff4319c98646b6d54477b9f512e944b9f5
parent 46963aa
2 files changed +24 -18
modified ci-broker.md
@@ -74,6 +74,23 @@ triggers:
      - !Branch "main"
~~~

+
~~~{#broker-with-concurrent-adapters.yaml .file .yaml}
+
db: ci-broker.db
+
report_dir: reports
+
queue_len_interval: 1min
+
adapters:
+
  mcadapterface:
+
    command: ./adapter.sh
+
    env:
+
      RADICLE_NATIVE_CI: native-ci.yaml
+
    sensitive_env:
+
      API_KEY: xyzzy
+
triggers:
+
  - adapter: mcadapterface
+
    filters:
+
      - !Branch "main"
+
~~~
+

~~~{#broker-with-two-triggers.yaml .file .yaml}
db: ci-broker.db
report_dir: reports
@@ -302,8 +319,8 @@ output is in the JSON format. It does not try to make sure the JSON
matches the YAML semantically.

~~~scenario
-
given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
-
when I run cib --config broker.yaml config --output actual.json
+
given a Radicle node, with CI configured with broker-with-concurrent-adapters.yaml and adapter dummy.sh
+
when I run cib --config broker-with-concurrent-adapters.yaml config --output actual.json
when I run jq . actual.json
then command is successful
~~~
modified src/config.rs
@@ -19,20 +19,6 @@ const DEFAULT_MAX_RUN_TIME: Duration = Duration::from_secs(3600);
const DEFAULT_QUEUE_LEN_INTERVAL: Duration = Duration::from_secs(3600);
const DEFAULT_STATUS_PAGE_UPDATE_INTERVAL: u64 = 10;

-
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
-
struct NonzeroCount {
-
    count: Option<usize>,
-
}
-

-
impl NonzeroCount {
-
    fn count(&self) -> usize {
-
        match self.count {
-
            None | Some(1) => 1,
-
            Some(n) => n,
-
        }
-
    }
-
}
-

#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
@@ -53,7 +39,7 @@ pub struct Config {
    queue_len_interval: Duration,

    #[serde(default)]
-
    concurrent_adapters: NonzeroCount,
+
    concurrent_adapters: Option<usize>,
}

fn default_max_run_time() -> Duration {
@@ -76,7 +62,10 @@ impl Config {
    }

    pub fn concurrent_adapters(&self) -> usize {
-
        self.concurrent_adapters.count()
+
        match self.concurrent_adapters {
+
            None | Some(0) => 1,
+
            Some(n) => n,
+
        }
    }

    pub fn to_adapters(&self) -> Result<Adapters, AdapterError> {