mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 23:49:53 +08:00
feat: 迁移所有配置到数据库,并支持运行时重载 (#364)
This commit is contained in:
@@ -17,21 +17,20 @@ use std::future::Future;
|
||||
use std::sync::Arc;
|
||||
|
||||
use bilibili::BiliClient;
|
||||
use once_cell::sync::Lazy;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use task::{http_server, video_downloader};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tokio_util::task::TaskTracker;
|
||||
|
||||
use crate::config::{ARGS, CONFIG};
|
||||
use crate::config::{ARGS, VersionedConfig};
|
||||
use crate::database::setup_database;
|
||||
use crate::utils::init_logger;
|
||||
use crate::utils::signal::terminate;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
init();
|
||||
let connection = init().await;
|
||||
let bili_client = Arc::new(BiliClient::new());
|
||||
let connection = Arc::new(setup_database().await);
|
||||
|
||||
let token = CancellationToken::new();
|
||||
let tracker = TaskTracker::new();
|
||||
@@ -74,12 +73,17 @@ fn spawn_task(
|
||||
});
|
||||
}
|
||||
|
||||
/// 初始化日志系统,打印欢迎信息,加载配置文件
|
||||
fn init() {
|
||||
/// 初始化日志系统、打印欢迎信息,初始化数据库连接和全局配置,最终返回数据库连接
|
||||
async fn init() -> Arc<DatabaseConnection> {
|
||||
init_logger(&ARGS.log_level);
|
||||
info!("欢迎使用 Bili-Sync,当前程序版本:{}", config::version());
|
||||
info!("项目地址:https://github.com/amtoaer/bili-sync");
|
||||
Lazy::force(&CONFIG);
|
||||
let connection = Arc::new(setup_database().await.expect("数据库初始化失败"));
|
||||
info!("数据库初始化完成");
|
||||
VersionedConfig::init(&connection).await.expect("配置初始化失败");
|
||||
info!("配置初始化完成");
|
||||
|
||||
connection
|
||||
}
|
||||
|
||||
async fn handle_shutdown(tracker: TaskTracker, token: CancellationToken) {
|
||||
|
||||
Reference in New Issue
Block a user