feat: init process: apply DB migrations and job scheduler
This commit is contained in:
parent
963ce0174b
commit
21a283d138
42
src/main.rs
42
src/main.rs
|
@ -1,20 +1,10 @@
|
||||||
/*
|
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
*
|
//
|
||||||
* This program is free software: you can redistribute it and/or modify
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
error::InternalError, http::StatusCode, middleware as actix_middleware, web::Data as WebData,
|
error::InternalError, http::StatusCode, middleware as actix_middleware, web::Data as WebData,
|
||||||
|
@ -39,12 +29,15 @@ pub const PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
|
||||||
|
|
||||||
pub type AppCtx = WebData<ctx::ArcCtx>;
|
pub type AppCtx = WebData<ctx::ArcCtx>;
|
||||||
|
|
||||||
|
mod api;
|
||||||
|
mod complaince;
|
||||||
mod ctx;
|
mod ctx;
|
||||||
mod db;
|
mod db;
|
||||||
mod docker;
|
mod docker;
|
||||||
|
mod docker_compose;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod compliance;
|
|
||||||
mod git;
|
mod git;
|
||||||
|
mod runner;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
@ -75,13 +68,17 @@ async fn main() -> std::io::Result<()> {
|
||||||
);
|
);
|
||||||
|
|
||||||
let settings = Settings::new().unwrap();
|
let settings = Settings::new().unwrap();
|
||||||
|
settings.init();
|
||||||
|
let ctx = AppCtx::new(Arc::new(Ctx::new(settings.clone()).await));
|
||||||
|
ctx.db.migrate().await.unwrap();
|
||||||
|
serve(settings, ctx).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn serve(settings: Settings, ctx: AppCtx) -> std::io::Result<()> {
|
async fn serve(settings: Settings, ctx: AppCtx) -> std::io::Result<()> {
|
||||||
let ip = settings.server.get_ip();
|
let ip = settings.server.get_ip();
|
||||||
let workers = settings.server.workers.unwrap_or_else(num_cpus::get);
|
let workers = settings.server.workers.unwrap_or_else(num_cpus::get);
|
||||||
|
let scheduler = runner::Scheduler::spawn(ctx.clone()).await;
|
||||||
|
|
||||||
info!("Starting server on: http://{}", ip);
|
info!("Starting server on: http://{}", ip);
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
|
@ -103,7 +100,9 @@ async fn serve(settings: Settings, ctx: AppCtx) -> std::io::Result<()> {
|
||||||
.bind(ip)
|
.bind(ip)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await?;
|
||||||
|
scheduler.stop().await;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
|
@ -115,8 +114,5 @@ pub fn get_json_err() -> JsonConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
// crate::api::v1::services(cfg);
|
crate::api::v1::services(cfg);
|
||||||
// crate::pages::services(cfg);
|
|
||||||
// crate::static_assets::services(cfg);
|
|
||||||
// crate::serve::services(cfg);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue