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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
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]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.81"
|
version = "0.1.81"
|
||||||
|
@ -146,6 +177,7 @@ name = "autotasker"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"argh",
|
||||||
"axum",
|
"axum",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -20,4 +20,5 @@ log = "0.4.22"
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.3"
|
||||||
tower-http = { version = "0.5.2", features = ["fs"] }
|
tower-http = { version = "0.5.2", features = ["fs"] }
|
||||||
tokio-cron-scheduler = "0.10.2"
|
tokio-cron-scheduler = "0.10.2"
|
||||||
|
argh = "0.1.12"
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ Unix-like
|
||||||
- [x] List the tasks availables.
|
- [x] List the tasks availables.
|
||||||
- [x] Run tasks in background.
|
- [x] Run tasks in background.
|
||||||
- [x] Store the logs and tasks runs in a sqlite DB.
|
- [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.
|
- [ ] OpenMetrics exporter to alert when a task failed.
|
||||||
- [ ] External alerting when a task failed.
|
- [ ] External alerting when a task failed.
|
||||||
- [ ] Run task via webhook, with a webhook token.
|
- [ ] Run task via webhook, with a webhook token.
|
||||||
|
|
11
TODO.md
11
TODO.md
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [x] Implement basic scheduler
|
- [ ] Implement support for webhook and debouncing of webhook
|
||||||
- [x] Add basic CSS
|
- [ ] Implement basic auth with HTTP basic auth (to trigger and see logs only)
|
||||||
- [ ] Implement basic auth with OAuth2
|
- [ ] add CSS badge and color code on job status
|
||||||
- [ ] Validating config file
|
- [ ] Validating config file
|
||||||
- validate schedule CRON syntax
|
- validate schedule CRON syntax
|
||||||
- [ ] Load config file from `/etc/`
|
- [ ] Implement basic auth with OAuth2
|
||||||
- [ ] Add `Dockerfile` and docker-compose example
|
- [ ] Add `Dockerfile` and docker-compose example
|
||||||
- [ ] Add CI/CD to build docker image
|
- [ ] Add CI/CD to build docker image
|
||||||
- [ ] Add configuration to limit the logs head and tail
|
- [ ] Add configuration to limit the logs head and tail
|
||||||
|
@ -30,3 +30,6 @@
|
||||||
|
|
||||||
- [x] setup sqlite
|
- [x] setup sqlite
|
||||||
- [x] store of task run logs in 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 executor;
|
||||||
mod scheduler;
|
mod scheduler;
|
||||||
|
|
||||||
|
use argh::FromArgs;
|
||||||
use log::info;
|
use log::info;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
|
@ -27,8 +28,16 @@ pub struct AppState {
|
||||||
templating_env: Environment<'static>
|
templating_env: Environment<'static>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_config() -> Result<Config> {
|
#[derive(Debug, FromArgs)]
|
||||||
let inp_def_yaml = fs::read_to_string("./config.yaml")
|
/// 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");
|
.expect("Should have been able to read the the config file");
|
||||||
|
|
||||||
serde_yaml::from_str(&inp_def_yaml)
|
serde_yaml::from_str(&inp_def_yaml)
|
||||||
|
@ -60,6 +69,7 @@ fn build_templating_env() -> Environment<'static> {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
let flags: CliFlags = argh::from_env();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
info!("Starting autotasker");
|
info!("Starting autotasker");
|
||||||
|
@ -68,7 +78,12 @@ async fn main() -> Result<()> {
|
||||||
// start channel to talk to executor daemon
|
// start channel to talk to executor daemon
|
||||||
let (tx, rx) = mpsc::channel::<ExecutorOrder>(32);
|
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 {
|
let state = AppState {
|
||||||
config,
|
config,
|
||||||
|
|
Loading…
Reference in a new issue