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
|
||||
|
||||
- [ ] Implement basic scheduler
|
||||
- [x] Implement basic scheduler
|
||||
- [x] Add basic CSS
|
||||
- [ ] Implement basic auth with OAuth2
|
||||
- [ ] Validating config file
|
||||
- validate schedule CRON syntax
|
||||
- [ ] Load config file from `/etc/`
|
||||
- [ ] Add CSS style with bootstrap
|
||||
- [ ] Add `Dockerfile` and docker-compose example
|
||||
- [ ] Add CI/CD to build docker image
|
||||
- [ ] 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 axum::routing::get;
|
||||
use axum::Router;
|
||||
use minijinja::Environment;
|
||||
use minijinja::{context, Environment};
|
||||
use scheduler::run_scheduler;
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||
use sqlx::{ConnectOptions, Pool, Sqlite};
|
||||
|
@ -35,18 +35,7 @@ fn get_config() -> Result<Config> {
|
|||
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
|
||||
}
|
||||
|
||||
|
||||
#[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");
|
||||
fn build_templating_env() -> Environment<'static> {
|
||||
let mut templating_env = Environment::new();
|
||||
|
||||
templating_env
|
||||
|
@ -61,12 +50,31 @@ async fn main() -> Result<()> {
|
|||
.add_template(&path, &content)
|
||||
.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 {
|
||||
config,
|
||||
db: pool,
|
||||
executor_tx: Arc::new(tx),
|
||||
templating_env
|
||||
templating_env: build_templating_env()
|
||||
};
|
||||
|
||||
// start executor daemon
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
{% block body %}{% endblock %}
|
||||
</main>
|
||||
<footer>
|
||||
Autotasker
|
||||
Autotasker {{ gl.instance.version }}
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue