Commit 14a09798 authored by Daniel Brüning's avatar Daniel Brüning
Browse files

Added an option to either disable the scan for contests on a server start or...

Added an option to either disable the scan for contests on a server start or scan for contents without starting the server
parent f15306ab
Pipeline #147 failed with stage
in 3 minutes and 34 seconds
...@@ -57,6 +57,7 @@ pub struct Config { ...@@ -57,6 +57,7 @@ pub struct Config {
oauth_providers: Option<Vec<oauth_provider::OauthProvider>>, oauth_providers: Option<Vec<oauth_provider::OauthProvider>>,
database_file: Option<PathBuf>, database_file: Option<PathBuf>,
template: Option<String>, template: Option<String>,
no_contest_scan: Option<bool>,
} }
fn read_config_from_file(file: &Path) -> Config { fn read_config_from_file(file: &Path) -> Config {
...@@ -92,6 +93,9 @@ fn read_config_from_file(file: &Path) -> Config { ...@@ -92,6 +93,9 @@ fn read_config_from_file(file: &Path) -> Config {
if config.template.is_none() { if config.template.is_none() {
config.template = Some("default".to_string()) config.template = Some("default".to_string())
} }
if config.no_contest_scan.is_none() {
config.no_contest_scan = Some(false)
}
println!("OAuth providers will be told to redirect to {}", config.self_url.as_ref().unwrap()); println!("OAuth providers will be told to redirect to {}", config.self_url.as_ref().unwrap());
...@@ -116,6 +120,14 @@ struct Opt { ...@@ -116,6 +120,14 @@ struct Opt {
/// Reset password of admin user (user_id=1) /// Reset password of admin user (user_id=1)
#[structopt(short = "a", long = "reset-admin-pw")] #[structopt(short = "a", long = "reset-admin-pw")]
resetadminpw: bool, resetadminpw: bool,
/// Run medal without scanning for contests
#[structopt(short = "S", long = "no-contest-scan")]
nocontestscan: bool,
/// Scan for contests without starting medal
#[structopt(short = "s", long = "only-contest-scan")]
onlycontestscan: bool,
} }
fn read_contest(p: &path::PathBuf) -> Option<Contest> { fn read_contest(p: &path::PathBuf) -> Option<Contest> {
...@@ -214,6 +226,9 @@ fn main() { ...@@ -214,6 +226,9 @@ fn main() {
if opt.port.is_some() { if opt.port.is_some() {
config.port = opt.port; config.port = opt.port;
} }
if opt.nocontestscan {
config.no_contest_scan = Some(true);
}
let mut conn = match config.database_file { let mut conn = match config.database_file {
Some(ref path) => { Some(ref path) => {
...@@ -230,9 +245,13 @@ fn main() { ...@@ -230,9 +245,13 @@ fn main() {
println!("applying migrations …"); println!("applying migrations …");
db_apply_migrations::test(&mut conn); db_apply_migrations::test(&mut conn);
if opt.onlycontestscan == true || config.no_contest_scan == Some(false) {
println!("scanning for contests …"); println!("scanning for contests …");
refresh_all_contests(&mut conn); refresh_all_contests(&mut conn);
println!("finished")
}
if opt.onlycontestscan == false {
add_admin_user(&mut conn, opt.resetadminpw); add_admin_user(&mut conn, opt.resetadminpw);
match start_server(conn, config) { match start_server(conn, config) {
...@@ -241,6 +260,7 @@ fn main() { ...@@ -241,6 +260,7 @@ fn main() {
}; };
println!("Could not run server. Is the port already in use?"); println!("Could not run server. Is the port already in use?");
}
} }
#[cfg(test)] #[cfg(test)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment