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 {
|
||||
/// Path to the repo's tablejohn database.
|
||||
pub db: PathBuf,
|
||||
|
||||
/// Path to the git repo.
|
||||
pub repo: Option<PathBuf>,
|
||||
|
||||
/// Path to the bench repo.
|
||||
#[arg(long, short)]
|
||||
pub bench_repo: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Parser)]
|
||||
pub enum Command {
|
||||
Server(ServerCommand),
|
||||
Runner,
|
||||
// TODO bench script command?
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Parser)]
|
||||
|
|
@ -23,9 +29,11 @@ pub struct Args {
|
|||
/// Path to the config file.
|
||||
#[arg(long, short)]
|
||||
pub config: Option<PathBuf>,
|
||||
|
||||
/// Enable increasingly more verbose output
|
||||
#[arg(long, short, action = clap::ArgAction::Count)]
|
||||
pub verbose: u8,
|
||||
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ mod args;
|
|||
mod config;
|
||||
mod runner;
|
||||
mod server;
|
||||
mod somehow;
|
||||
mod shared;
|
||||
mod somehow;
|
||||
|
||||
use std::{io, process};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,22 +49,34 @@ async fn open_db(db_path: &Path) -> sqlx::Result<SqlitePool> {
|
|||
Ok(pool)
|
||||
}
|
||||
|
||||
fn open_repo(repo_path: &Path) -> somehow::Result<ThreadSafeRepository> {
|
||||
info!(path = %repo_path.display(), "Opening repo");
|
||||
Ok(ThreadSafeRepository::open(repo_path)?)
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub(self) struct Repo(Arc<ThreadSafeRepository>);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(self) struct BenchRepo(Arc<ThreadSafeRepository>);
|
||||
|
||||
#[derive(Clone, FromRef)]
|
||||
pub struct Server {
|
||||
config: &'static Config,
|
||||
db: SqlitePool,
|
||||
repo: Option<Arc<ThreadSafeRepository>>,
|
||||
repo: Option<Repo>,
|
||||
bench_repo: Option<BenchRepo>,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
pub async fn new(config: &'static Config, command: ServerCommand) -> somehow::Result<Self> {
|
||||
let repo = if let Some(repo) = command.repo.as_ref() {
|
||||
Some(Arc::new(open_repo(repo)?))
|
||||
let repo = if let Some(path) = command.repo.as_ref() {
|
||||
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 {
|
||||
None
|
||||
};
|
||||
|
|
@ -73,6 +85,7 @@ impl Server {
|
|||
config,
|
||||
db: open_db(&command.db).await?,
|
||||
repo,
|
||||
bench_repo,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +93,7 @@ impl Server {
|
|||
if let Some(repo) = self.repo.clone() {
|
||||
select! {
|
||||
e = web::run(self.clone()) => e,
|
||||
() = recurring::run(self.clone(), repo) => Ok(()),
|
||||
() = recurring::run(self.clone(), repo, self.bench_repo.clone()) => Ok(()),
|
||||
}
|
||||
} else {
|
||||
web::run(self.clone()).await
|
||||
|
|
|
|||
|
|
@ -6,14 +6,11 @@
|
|||
mod queue;
|
||||
mod repo;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gix::ThreadSafeRepository;
|
||||
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 {
|
||||
if let Err(e) = repo::update(&state.db, repo).await {
|
||||
error!("Error updating repo:\n{e:?}");
|
||||
|
|
@ -31,7 +28,7 @@ async fn recurring_task(state: &Server, repo: Arc<ThreadSafeRepository>) {
|
|||
.await;
|
||||
}
|
||||
|
||||
pub async fn run(server: Server, repo: Arc<ThreadSafeRepository>) {
|
||||
pub(super) async fn run(server: Server, repo: Repo, bench_repo: Option<BenchRepo>) {
|
||||
loop {
|
||||
recurring_task(&server, repo.clone()).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.
|
||||
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use futures::TryStreamExt;
|
||||
use gix::{
|
||||
objs::Kind, prelude::ObjectIdExt, refs::Reference, ObjectId, Repository, ThreadSafeRepository,
|
||||
};
|
||||
use gix::{objs::Kind, prelude::ObjectIdExt, refs::Reference, ObjectId, Repository};
|
||||
use sqlx::{Acquire, SqliteConnection, SqlitePool};
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::{server::util, somehow};
|
||||
use crate::{
|
||||
server::{util, Repo},
|
||||
somehow,
|
||||
};
|
||||
|
||||
async fn get_all_commit_hashes_from_db(
|
||||
conn: &mut SqliteConnection,
|
||||
|
|
@ -227,9 +228,9 @@ async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> somehow::R
|
|||
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");
|
||||
let thread_local_repo = repo.to_thread_local();
|
||||
let thread_local_repo = repo.0.to_thread_local();
|
||||
let mut tx = db.begin().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
|
||||
// keeps it from blocking the entire tokio worker.
|
||||
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??;
|
||||
debug!("Found {} new commits in repo", new.len());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue