Repository navigation
Preselect the configured interview length #584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -630,6 +630,33 @@ pub fn max_concurrent_interviews( | |
| } | ||
| } | ||
|
|
||
| /// The length `CODETRIAL_DURATION_MIN` stands for, held to the range the | ||
| /// endpoints offer, and what to say when it is not used as written: unreadable, | ||
| /// so the built-in length applies, or outside the range, so it is clamped. | ||
| /// One function for both, so the number in the message is the one the server | ||
| /// runs on and the operator who mistyped is not left guessing. | ||
| pub fn configured_duration(value: Option<&str>) -> (u32, Option<String>) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| let value = value.map(str::trim).unwrap_or_default(); | ||
| if value.is_empty() { | ||
| return (DEFAULT_DURATION_MIN, None); | ||
| } | ||
| let (reason, used) = match value.parse::<u32>() { | ||
| Ok(minutes) if (MIN_DURATION_MIN..=MAX_DURATION_MIN).contains(&minutes) => { | ||
| return (minutes, None); | ||
| } | ||
| Ok(minutes) => ( | ||
| format!("is outside {MIN_DURATION_MIN} to {MAX_DURATION_MIN}"), | ||
| minutes.clamp(MIN_DURATION_MIN, MAX_DURATION_MIN), | ||
| ), | ||
| Err(_) => ( | ||
| "is not a usable number of minutes".to_string(), | ||
| DEFAULT_DURATION_MIN, | ||
| ), | ||
| }; | ||
| let warning = format!("codetrial: CODETRIAL_DURATION_MIN {value:?} {reason}; read as {used}"); | ||
| (used, Some(warning)) | ||
| } | ||
|
|
||
| fn optional_u32(values: &BTreeMap<String, String>, key: &str, default: u32) -> u32 { | ||
| values | ||
| .get(key) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,7 @@ use std::collections::BTreeMap; | |
| use std::path::PathBuf; | ||
| use std::sync::Arc; | ||
|
|
||
| use codetrial::config::{ | ||
| AgentConfig, DEFAULT_DURATION_MIN, DEFAULT_ROOM_PREFIX, DEFAULT_WEB_ADDR, DEFAULT_WEB_DIR, | ||
| }; | ||
| use codetrial::config::{AgentConfig, DEFAULT_ROOM_PREFIX, DEFAULT_WEB_ADDR, DEFAULT_WEB_DIR}; | ||
| use codetrial::web::{RoomDispatcher, WebServerConfig}; | ||
|
|
||
| /// One installation keeps its config file and its account database together in | ||
|
|
@@ -355,6 +353,7 @@ fn web_server_config( | |
| allowed_hosts: allowed_hosts(values)?, | ||
| compiler_explorer_enabled: compiler_explorer_enabled(values), | ||
| guest_mode_enabled: guest_mode_enabled(values), | ||
| default_duration_min: interview_duration_min(values), | ||
|
RWong04 marked this conversation as resolved.
Resolved
RWong04 marked this conversation as resolved.
Resolved
|
||
| recording, | ||
| pool, | ||
| probe_provider_quota: true, | ||
|
|
@@ -400,6 +399,10 @@ fn run_web(options: CliOptions) -> Result<(), String> { | |
| let max_concurrent = read_max_concurrent(&values); | ||
|
|
||
| let production = is_production(&values); | ||
|
|
||
| if let Some(warning) = configured_duration(&values).1 { | ||
| eprintln!("{warning}"); | ||
| } | ||
| let pool = web_provider_pool(&values, &options, production)?; | ||
|
|
||
| let mut config = web_server_config(&values, pool, production, &options)?; | ||
|
|
@@ -1232,13 +1235,17 @@ fn recording_needs_verified_identity(recording: bool, oauth: bool) -> Result<(), | |
| Ok(()) | ||
| } | ||
|
|
||
| /// The configured interview length, which is what a recording's maximum | ||
| /// duration has to clear. Read here rather than through `load_from_pairs` | ||
| /// because `codetrial web` deliberately runs without a full agent config. | ||
| /// The configured interview length, held to the range the endpoints offer, | ||
| /// which is what a recording's maximum duration has to clear. Read here rather | ||
| /// than through `load_from_pairs`, because `codetrial web` deliberately runs | ||
| /// without a full agent config. | ||
| fn interview_duration_min(values: &BTreeMap<String, String>) -> u32 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parser tests cover |
||
| nonempty(values, "CODETRIAL_DURATION_MIN") | ||
| .and_then(|value| value.parse().ok()) | ||
| .unwrap_or(DEFAULT_DURATION_MIN) | ||
| configured_duration(values).0 | ||
| } | ||
|
|
||
| /// [`codetrial::config::configured_duration`] over the config values. | ||
| fn configured_duration(values: &BTreeMap<String, String>) -> (u32, Option<String>) { | ||
| codetrial::config::configured_duration(values.get("CODETRIAL_DURATION_MIN").map(String::as_str)) | ||
| } | ||
|
|
||
| /// `CODETRIAL_ALLOWED_HOSTS`, a comma-separated list of `Host` values. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.