This commit is contained in:
1 parent
d74db2096c
commit
8c763786c1
25 files changed
+3614
-407
No files matched your search
@@ -1,12 +1,8 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
dedup::Dedup,
|
||||
gitea::{GiteaAPI, WebhookType},
|
||||
open_router::OpenRouterClient,
|
||||
sandbox::SandboxConfig,
|
||||
state::AppState,
|
||||
bot::Bot, dedup::Dedup, gitea::GiteaAPI, job_queue::JobQueue, open_router::OpenRouterClient,
|
||||
sandbox::SandboxConfig, state::AppState,
|
||||
};
|
||||
|
||||
use dotenvy::dotenv;
|
||||
@@ -19,13 +15,16 @@ mod api;
|
||||
mod bot;
|
||||
mod bot_actions;
|
||||
mod consts;
|
||||
mod db;
|
||||
mod dedup;
|
||||
mod env;
|
||||
mod errors;
|
||||
mod gitea;
|
||||
mod job_queue;
|
||||
mod metrics;
|
||||
mod open_router;
|
||||
mod sandbox;
|
||||
mod schemas;
|
||||
mod state;
|
||||
mod text;
|
||||
|
||||
@@ -38,6 +37,11 @@ const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
fn main() -> anyhow::Result<()> {
|
||||
dotenv().ok();
|
||||
|
||||
// Sous-commande de migration : `steep-server migration <generate|apply|...>`.
|
||||
if std::env::args().nth(1).as_deref() == Some("migration") {
|
||||
return tokio::runtime::Runtime::new()?.block_on(run_migrations());
|
||||
}
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(fmt::layer())
|
||||
.with(
|
||||
@@ -63,6 +67,24 @@ fn main() -> anyhow::Result<()> {
|
||||
tokio::runtime::Runtime::new()?.block_on(run())
|
||||
}
|
||||
|
||||
async fn run_migrations() -> anyhow::Result<()> {
|
||||
let database_url = env::try_get_env("DATABASE_URL")?;
|
||||
let db = db::open(&database_url).await?;
|
||||
|
||||
let migrations = match std::env::var("MIGRATIONS_DIR") {
|
||||
Ok(dir) => std::path::PathBuf::from(dir),
|
||||
Err(_) => std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("toasty"),
|
||||
};
|
||||
let config =
|
||||
toasty_cli::Config::new().migration(toasty_cli::MigrationConfig::new().path(migrations));
|
||||
|
||||
toasty_cli::ToastyCli::with_config(db, config)
|
||||
.parse_and_run()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn run() -> anyhow::Result<()> {
|
||||
let config = env::load_config()?;
|
||||
|
||||
@@ -101,10 +123,9 @@ async fn run() -> anyhow::Result<()> {
|
||||
);
|
||||
}
|
||||
|
||||
let redis_conn = apalis_redis::connect(config.redis_url.clone()).await?;
|
||||
let storage: apalis_redis::RedisStorage<WebhookType> =
|
||||
apalis_redis::RedisStorage::new(redis_conn.clone());
|
||||
let dedup = Dedup::new(redis_conn);
|
||||
let db = db::connect(&config.database_url).await?;
|
||||
let dedup = Dedup::new(db.clone());
|
||||
let queue = JobQueue::new(db);
|
||||
|
||||
let bot = Bot::new(
|
||||
gitea_api,
|
||||
@@ -113,12 +134,13 @@ async fn run() -> anyhow::Result<()> {
|
||||
config.open_router_model.clone(),
|
||||
sandbox,
|
||||
dedup.clone(),
|
||||
queue.clone(),
|
||||
);
|
||||
|
||||
let app_state = AppState {
|
||||
storage: storage.clone(),
|
||||
bot_name: gitea_user.login.clone(),
|
||||
queue,
|
||||
dedup,
|
||||
bot_name: gitea_user.login.clone(),
|
||||
config,
|
||||
};
|
||||
|
||||
@@ -143,7 +165,7 @@ async fn run() -> anyhow::Result<()> {
|
||||
tokio::select! {
|
||||
result = async {
|
||||
tokio::try_join!(
|
||||
bot.start(storage, shutdown.clone()),
|
||||
bot.start(shutdown.clone()),
|
||||
api::start(app_state, shutdown.clone()),
|
||||
signal
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user