feat: add cli interface to change config
This commit is contained in:
parent
544d8a6f89
commit
481d59e963
5 changed files with 59 additions and 8 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -115,6 +115,37 @@ version = "1.0.86"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||
|
||||
[[package]]
|
||||
name = "argh"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7af5ba06967ff7214ce4c7419c7d185be7ecd6cc4965a8f6e1d8ce0398aad219"
|
||||
dependencies = [
|
||||
"argh_derive",
|
||||
"argh_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "argh_derive"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56df0aeedf6b7a2fc67d06db35b09684c3e8da0c95f8f27685cb17e08413d87a"
|
||||
dependencies = [
|
||||
"argh_shared",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "argh_shared"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5693f39141bda5760ecc4111ab08da40565d1771038c4a0250f03457ec707531"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.81"
|
||||
|
@ -146,6 +177,7 @@ name = "autotasker"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"argh",
|
||||
"axum",
|
||||
"chrono",
|
||||
"clap",
|
||||
|
|
|
@ -20,4 +20,5 @@ log = "0.4.22"
|
|||
env_logger = "0.11.3"
|
||||
tower-http = { version = "0.5.2", features = ["fs"] }
|
||||
tokio-cron-scheduler = "0.10.2"
|
||||
argh = "0.1.12"
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ Unix-like
|
|||
- [x] List the tasks availables.
|
||||
- [x] Run tasks in background.
|
||||
- [x] Store the logs and tasks runs in a sqlite DB.
|
||||
- [ ] Schedule tasks (CRON-like).
|
||||
- [x] Schedule tasks (CRON-like).
|
||||
- [ ] OpenMetrics exporter to alert when a task failed.
|
||||
- [ ] External alerting when a task failed.
|
||||
- [ ] Run task via webhook, with a webhook token.
|
||||
|
|
11
TODO.md
11
TODO.md
|
@ -2,12 +2,12 @@
|
|||
|
||||
## TODO
|
||||
|
||||
- [x] Implement basic scheduler
|
||||
- [x] Add basic CSS
|
||||
- [ ] Implement basic auth with OAuth2
|
||||
- [ ] Implement support for webhook and debouncing of webhook
|
||||
- [ ] Implement basic auth with HTTP basic auth (to trigger and see logs only)
|
||||
- [ ] add CSS badge and color code on job status
|
||||
- [ ] Validating config file
|
||||
- validate schedule CRON syntax
|
||||
- [ ] Load config file from `/etc/`
|
||||
- [ ] Implement basic auth with OAuth2
|
||||
- [ ] Add `Dockerfile` and docker-compose example
|
||||
- [ ] Add CI/CD to build docker image
|
||||
- [ ] Add configuration to limit the logs head and tail
|
||||
|
@ -30,3 +30,6 @@
|
|||
|
||||
- [x] setup sqlite
|
||||
- [x] store of task run logs in sqlite
|
||||
- [x] Implement basic scheduler
|
||||
- [x] Add basic CSS
|
||||
- [x] Load config file from `/etc/`
|
||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -3,6 +3,7 @@ mod models;
|
|||
mod executor;
|
||||
mod scheduler;
|
||||
|
||||
use argh::FromArgs;
|
||||
use log::info;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use axum::routing::get;
|
||||
|
@ -27,8 +28,16 @@ pub struct AppState {
|
|||
templating_env: Environment<'static>
|
||||
}
|
||||
|
||||
fn get_config() -> Result<Config> {
|
||||
let inp_def_yaml = fs::read_to_string("./config.yaml")
|
||||
#[derive(Debug, FromArgs)]
|
||||
/// Autotasker daemon
|
||||
struct CliFlags {
|
||||
/// path to YAML config file to use to configure autotasker
|
||||
#[argh(option)]
|
||||
config: Option<String>,
|
||||
}
|
||||
|
||||
fn get_config(path: String) -> Result<Config> {
|
||||
let inp_def_yaml = fs::read_to_string(path)
|
||||
.expect("Should have been able to read the the config file");
|
||||
|
||||
serde_yaml::from_str(&inp_def_yaml)
|
||||
|
@ -60,6 +69,7 @@ fn build_templating_env() -> Environment<'static> {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let flags: CliFlags = argh::from_env();
|
||||
env_logger::init();
|
||||
|
||||
info!("Starting autotasker");
|
||||
|
@ -68,7 +78,12 @@ async fn main() -> Result<()> {
|
|||
// start channel to talk to executor daemon
|
||||
let (tx, rx) = mpsc::channel::<ExecutorOrder>(32);
|
||||
|
||||
let config: Config = get_config().expect("Cannot get config");
|
||||
let config_path = match flags.config {
|
||||
Some(v) => v,
|
||||
None => "/etc/autotasker/config.yaml".to_string()
|
||||
};
|
||||
info!("Using config file at {}", &config_path);
|
||||
let config: Config = get_config(config_path).expect("Cannot get config");
|
||||
|
||||
let state = AppState {
|
||||
config,
|
||||
|
|
Loading…
Reference in a new issue