mirror of
https://github.com/encounter/decomp.dev.git
synced 2026-07-10 03:18:48 -07:00
Create separate jobs db
This commit is contained in:
@@ -6,6 +6,7 @@ server:
|
||||
|
||||
db:
|
||||
url: sqlite:./db.sqlite
|
||||
jobs_url: sqlite:./jobs.sqlite
|
||||
|
||||
github:
|
||||
# Personal access token for public repo access
|
||||
|
||||
@@ -20,6 +20,7 @@ pub struct ServerConfig {
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct DbConfig {
|
||||
pub url: String,
|
||||
pub jobs_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
|
||||
+14
-7
@@ -2,7 +2,7 @@ mod jobs;
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use apalis::{
|
||||
layers::retry::{
|
||||
HasherRng, RetryPolicy,
|
||||
@@ -11,13 +11,13 @@ use apalis::{
|
||||
prelude::*,
|
||||
};
|
||||
use apalis_sqlite::{CompactType, SqliteStorage, fetcher::SqliteFetcher};
|
||||
use decomp_dev_core::config::{Config, WorkerConfig};
|
||||
use decomp_dev_core::config::{Config, DbConfig, WorkerConfig};
|
||||
use decomp_dev_db::Database;
|
||||
use decomp_dev_github::GitHub;
|
||||
pub use jobs::{
|
||||
ProcessWorkflowRunJob, RefreshProjectJob, process_refresh_project_job, process_workflow_run_job,
|
||||
};
|
||||
use sqlx::sqlite::SqlitePool;
|
||||
use sqlx::{Sqlite, migrate::MigrateDatabase, sqlite::SqlitePool};
|
||||
|
||||
/// Shared context available to all job handlers.
|
||||
#[derive(Clone)]
|
||||
@@ -45,11 +45,18 @@ pub struct JobStorage {
|
||||
|
||||
impl JobStorage {
|
||||
/// Set up job storage tables and create storage instances.
|
||||
pub async fn setup(pool: &SqlitePool) -> Result<Arc<Self>> {
|
||||
SqliteStorage::setup(pool).await?;
|
||||
pub async fn setup(db: &DbConfig) -> Result<Arc<Self>> {
|
||||
if !Sqlite::database_exists(&db.jobs_url).await.unwrap_or(false) {
|
||||
tracing::info!(url = %db.jobs_url, "Creating database");
|
||||
Sqlite::create_database(&db.jobs_url).await.context("Failed to create database")?;
|
||||
tracing::info!("Database created");
|
||||
}
|
||||
let pool =
|
||||
SqlitePool::connect(&db.jobs_url).await.context("Failed to connect to database")?;
|
||||
SqliteStorage::setup(&pool).await?;
|
||||
Ok(Arc::new(Self {
|
||||
workflow_run: SqliteStorage::new(pool),
|
||||
refresh_project: SqliteStorage::new(pool),
|
||||
workflow_run: SqliteStorage::new(&pool),
|
||||
refresh_project: SqliteStorage::new(&pool),
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ async fn main() {
|
||||
};
|
||||
let db = Database::new(&config.db).await.expect("Failed to open database");
|
||||
let github = GitHub::new(&config.github).await.expect("Failed to create GitHub client");
|
||||
let jobs = JobStorage::setup(&db.pool).await.expect("Failed to set up job storage");
|
||||
let jobs = JobStorage::setup(&config.db).await.expect("Failed to set up job storage");
|
||||
|
||||
let job_context = JobContext { config: config.clone(), db: db.clone(), github: github.clone() };
|
||||
let state = AppState { config: config.clone(), db: db.clone(), github, jobs };
|
||||
|
||||
Reference in New Issue
Block a user