Add --bench-script cli arg
This commit is contained in:
parent
e03617edda
commit
f84a5b288e
5 changed files with 42 additions and 23 deletions
|
|
@ -7,14 +7,20 @@ pub const VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_
|
||||||
pub struct ServerCommand {
|
pub struct ServerCommand {
|
||||||
/// Path to the repo's tablejohn database.
|
/// Path to the repo's tablejohn database.
|
||||||
pub db: PathBuf,
|
pub db: PathBuf,
|
||||||
|
|
||||||
/// Path to the git repo.
|
/// Path to the git repo.
|
||||||
pub repo: Option<PathBuf>,
|
pub repo: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Path to the bench repo.
|
||||||
|
#[arg(long, short)]
|
||||||
|
pub bench_repo: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, clap::Parser)]
|
#[derive(Debug, clap::Parser)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Server(ServerCommand),
|
Server(ServerCommand),
|
||||||
Runner,
|
Runner,
|
||||||
|
// TODO bench script command?
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, clap::Parser)]
|
#[derive(Debug, clap::Parser)]
|
||||||
|
|
@ -23,9 +29,11 @@ pub struct Args {
|
||||||
/// Path to the config file.
|
/// Path to the config file.
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
pub config: Option<PathBuf>,
|
pub config: Option<PathBuf>,
|
||||||
|
|
||||||
/// Enable increasingly more verbose output
|
/// Enable increasingly more verbose output
|
||||||
#[arg(long, short, action = clap::ArgAction::Count)]
|
#[arg(long, short, action = clap::ArgAction::Count)]
|
||||||
pub verbose: u8,
|
pub verbose: u8,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ mod args;
|
||||||
mod config;
|
mod config;
|
||||||
mod runner;
|
mod runner;
|
||||||
mod server;
|
mod server;
|
||||||
mod somehow;
|
|
||||||
mod shared;
|
mod shared;
|
||||||
|
mod somehow;
|
||||||
|
|
||||||
use std::{io, process};
|
use std::{io, process};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,22 +49,34 @@ async fn open_db(db_path: &Path) -> sqlx::Result<SqlitePool> {
|
||||||
Ok(pool)
|
Ok(pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_repo(repo_path: &Path) -> somehow::Result<ThreadSafeRepository> {
|
#[derive(Clone)]
|
||||||
info!(path = %repo_path.display(), "Opening repo");
|
pub(self) struct Repo(Arc<ThreadSafeRepository>);
|
||||||
Ok(ThreadSafeRepository::open(repo_path)?)
|
|
||||||
}
|
#[derive(Clone)]
|
||||||
|
pub(self) struct BenchRepo(Arc<ThreadSafeRepository>);
|
||||||
|
|
||||||
#[derive(Clone, FromRef)]
|
#[derive(Clone, FromRef)]
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
config: &'static Config,
|
config: &'static Config,
|
||||||
db: SqlitePool,
|
db: SqlitePool,
|
||||||
repo: Option<Arc<ThreadSafeRepository>>,
|
repo: Option<Repo>,
|
||||||
|
bench_repo: Option<BenchRepo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub async fn new(config: &'static Config, command: ServerCommand) -> somehow::Result<Self> {
|
pub async fn new(config: &'static Config, command: ServerCommand) -> somehow::Result<Self> {
|
||||||
let repo = if let Some(repo) = command.repo.as_ref() {
|
let repo = if let Some(path) = command.repo.as_ref() {
|
||||||
Some(Arc::new(open_repo(repo)?))
|
info!(path = %path.display(), "Opening repo");
|
||||||
|
let repo = ThreadSafeRepository::open(path)?;
|
||||||
|
Some(Repo(Arc::new(repo)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let bench_repo = if let Some(path) = command.bench_repo.as_ref() {
|
||||||
|
info!(path = %path.display(), "Opening repo");
|
||||||
|
let repo = ThreadSafeRepository::open(path)?;
|
||||||
|
Some(BenchRepo(Arc::new(repo)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
@ -73,6 +85,7 @@ impl Server {
|
||||||
config,
|
config,
|
||||||
db: open_db(&command.db).await?,
|
db: open_db(&command.db).await?,
|
||||||
repo,
|
repo,
|
||||||
|
bench_repo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,7 +93,7 @@ impl Server {
|
||||||
if let Some(repo) = self.repo.clone() {
|
if let Some(repo) = self.repo.clone() {
|
||||||
select! {
|
select! {
|
||||||
e = web::run(self.clone()) => e,
|
e = web::run(self.clone()) => e,
|
||||||
() = recurring::run(self.clone(), repo) => Ok(()),
|
() = recurring::run(self.clone(), repo, self.bench_repo.clone()) => Ok(()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
web::run(self.clone()).await
|
web::run(self.clone()).await
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,11 @@
|
||||||
mod queue;
|
mod queue;
|
||||||
mod repo;
|
mod repo;
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use gix::ThreadSafeRepository;
|
|
||||||
use tracing::{debug_span, error, Instrument};
|
use tracing::{debug_span, error, Instrument};
|
||||||
|
|
||||||
use super::Server;
|
use super::{BenchRepo, Repo, Server};
|
||||||
|
|
||||||
async fn recurring_task(state: &Server, repo: Arc<ThreadSafeRepository>) {
|
async fn recurring_task(state: &Server, repo: Repo) {
|
||||||
async {
|
async {
|
||||||
if let Err(e) = repo::update(&state.db, repo).await {
|
if let Err(e) = repo::update(&state.db, repo).await {
|
||||||
error!("Error updating repo:\n{e:?}");
|
error!("Error updating repo:\n{e:?}");
|
||||||
|
|
@ -31,7 +28,7 @@ async fn recurring_task(state: &Server, repo: Arc<ThreadSafeRepository>) {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(server: Server, repo: Arc<ThreadSafeRepository>) {
|
pub(super) async fn run(server: Server, repo: Repo, bench_repo: Option<BenchRepo>) {
|
||||||
loop {
|
loop {
|
||||||
recurring_task(&server, repo.clone()).await;
|
recurring_task(&server, repo.clone()).await;
|
||||||
tokio::time::sleep(server.config.repo_update_delay).await;
|
tokio::time::sleep(server.config.repo_update_delay).await;
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
//! Add new commits to the database and update the tracked refs.
|
//! Add new commits to the database and update the tracked refs.
|
||||||
|
|
||||||
use std::{collections::HashSet, sync::Arc};
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use gix::{
|
use gix::{objs::Kind, prelude::ObjectIdExt, refs::Reference, ObjectId, Repository};
|
||||||
objs::Kind, prelude::ObjectIdExt, refs::Reference, ObjectId, Repository, ThreadSafeRepository,
|
|
||||||
};
|
|
||||||
use sqlx::{Acquire, SqliteConnection, SqlitePool};
|
use sqlx::{Acquire, SqliteConnection, SqlitePool};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::{server::util, somehow};
|
use crate::{
|
||||||
|
server::{util, Repo},
|
||||||
|
somehow,
|
||||||
|
};
|
||||||
|
|
||||||
async fn get_all_commit_hashes_from_db(
|
async fn get_all_commit_hashes_from_db(
|
||||||
conn: &mut SqliteConnection,
|
conn: &mut SqliteConnection,
|
||||||
|
|
@ -227,9 +228,9 @@ async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> somehow::R
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(db: &SqlitePool, repo: Arc<ThreadSafeRepository>) -> somehow::Result<()> {
|
pub(super) async fn update(db: &SqlitePool, repo: Repo) -> somehow::Result<()> {
|
||||||
debug!("Updating repo");
|
debug!("Updating repo");
|
||||||
let thread_local_repo = repo.to_thread_local();
|
let thread_local_repo = repo.0.to_thread_local();
|
||||||
let mut tx = db.begin().await?;
|
let mut tx = db.begin().await?;
|
||||||
let conn = tx.acquire().await?;
|
let conn = tx.acquire().await?;
|
||||||
|
|
||||||
|
|
@ -244,7 +245,7 @@ pub async fn update(db: &SqlitePool, repo: Arc<ThreadSafeRepository>) -> somehow
|
||||||
// This can take a while for larger repos. Running it via spawn_blocking
|
// This can take a while for larger repos. Running it via spawn_blocking
|
||||||
// keeps it from blocking the entire tokio worker.
|
// keeps it from blocking the entire tokio worker.
|
||||||
let (refs, new) = tokio::task::spawn_blocking(move || {
|
let (refs, new) = tokio::task::spawn_blocking(move || {
|
||||||
get_all_refs_and_new_commits_from_repo(&repo.to_thread_local(), &old)
|
get_all_refs_and_new_commits_from_repo(&repo.0.to_thread_local(), &old)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
debug!("Found {} new commits in repo", new.len());
|
debug!("Found {} new commits in repo", new.len());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue