refactor: build templating env + add global template meta variable
This commit is contained in:
parent
de3defefa6
commit
544d8a6f89
3 changed files with 25 additions and 17 deletions
4
TODO.md
4
TODO.md
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [ ] Implement basic scheduler
|
- [x] Implement basic scheduler
|
||||||
|
- [x] Add basic CSS
|
||||||
- [ ] Implement basic auth with OAuth2
|
- [ ] Implement basic auth with OAuth2
|
||||||
- [ ] Validating config file
|
- [ ] Validating config file
|
||||||
- validate schedule CRON syntax
|
- validate schedule CRON syntax
|
||||||
- [ ] Load config file from `/etc/`
|
- [ ] Load config file from `/etc/`
|
||||||
- [ ] Add CSS style with bootstrap
|
|
||||||
- [ ] 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
|
||||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -7,7 +7,7 @@ use log::info;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use minijinja::Environment;
|
use minijinja::{context, Environment};
|
||||||
use scheduler::run_scheduler;
|
use scheduler::run_scheduler;
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||||
use sqlx::{ConnectOptions, Pool, Sqlite};
|
use sqlx::{ConnectOptions, Pool, Sqlite};
|
||||||
|
@ -35,18 +35,7 @@ fn get_config() -> Result<Config> {
|
||||||
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
|
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_templating_env() -> Environment<'static> {
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<()> {
|
|
||||||
env_logger::init();
|
|
||||||
|
|
||||||
info!("Starting autotasker");
|
|
||||||
let pool = prepare_database().await.context("Prepare db")?;
|
|
||||||
|
|
||||||
// start channel to talk to executor daemon
|
|
||||||
let (tx, rx) = mpsc::channel::<ExecutorOrder>(32);
|
|
||||||
|
|
||||||
let config: Config = get_config().expect("Cannot get config");
|
|
||||||
let mut templating_env = Environment::new();
|
let mut templating_env = Environment::new();
|
||||||
|
|
||||||
templating_env
|
templating_env
|
||||||
|
@ -61,12 +50,31 @@ async fn main() -> Result<()> {
|
||||||
.add_template(&path, &content)
|
.add_template(&path, &content)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
templating_env.add_global("gl", context! {
|
||||||
|
instance => context! {
|
||||||
|
version => "1.243".to_string()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
templating_env
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
env_logger::init();
|
||||||
|
|
||||||
|
info!("Starting autotasker");
|
||||||
|
let pool = prepare_database().await.context("Prepare db")?;
|
||||||
|
|
||||||
|
// start channel to talk to executor daemon
|
||||||
|
let (tx, rx) = mpsc::channel::<ExecutorOrder>(32);
|
||||||
|
|
||||||
|
let config: Config = get_config().expect("Cannot get config");
|
||||||
|
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
config,
|
config,
|
||||||
db: pool,
|
db: pool,
|
||||||
executor_tx: Arc::new(tx),
|
executor_tx: Arc::new(tx),
|
||||||
templating_env
|
templating_env: build_templating_env()
|
||||||
};
|
};
|
||||||
|
|
||||||
// start executor daemon
|
// start executor daemon
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer>
|
||||||
Autotasker
|
Autotasker {{ gl.instance.version }}
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue