Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webserver): implement new storage layer for repository meta #1750

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 93 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/tabby-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::{
path::repositories_dir,
terminal::{HeaderFormat, InfoMessage},
SourceFile,
};

#[derive(Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -145,6 +146,10 @@ impl Default for ServerConfig {
#[async_trait]
pub trait RepositoryAccess: Send + Sync {
async fn list_repositories(&self) -> Result<Vec<RepositoryConfig>>;

boxbeam marked this conversation as resolved.
Show resolved Hide resolved
fn start_snapshot(&self, _version: u64) {}
fn process_file(&self, _version: u64, _file: SourceFile) {}
fn finish_snapshot(&self, _version: u64) {}
}

pub struct ConfigRepositoryAccess;
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use path::dataset_dir;
use serde::{Deserialize, Serialize};
use serde_jsonlines::JsonLinesReader;

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
pub struct SourceFile {
pub git_url: String,
pub filepath: String,
Expand Down
30 changes: 24 additions & 6 deletions crates/tabby-scheduler/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use lazy_static::lazy_static;
use serde_jsonlines::WriteExt;
use tabby_common::{
config::RepositoryConfig,
config::{RepositoryAccess, RepositoryConfig},
path::{dataset_dir, dependency_file},
DependencyFile, SourceFile,
};
Expand All @@ -25,11 +25,21 @@
use crate::utils::tqdm;

trait RepositoryExt {
fn create_dataset(&self, writer: &mut impl Write) -> Result<()>;
fn create_dataset(
&self,
writer: &mut impl Write,
access: &impl RepositoryAccess,
snapshot_version: u64,
) -> Result<()>;
}

impl RepositoryExt for RepositoryConfig {
fn create_dataset(&self, writer: &mut impl Write) -> Result<()> {
fn create_dataset(
&self,
writer: &mut impl Write,
access: &impl RepositoryAccess,
snapshot_version: u64,
) -> Result<()> {

Check warning on line 42 in crates/tabby-scheduler/src/dataset.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/dataset.rs#L37-L42

Added lines #L37 - L42 were not covered by tests
let dir = self.dir();

let walk_dir_iter = || {
Expand Down Expand Up @@ -70,7 +80,8 @@
language,
content: file_content,
};
writer.write_json_lines([source_file])?;
writer.write_json_lines([source_file.clone()])?;
access.process_file(snapshot_version.clone(), source_file);

Check warning on line 84 in crates/tabby-scheduler/src/dataset.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/dataset.rs#L83-L84

Added lines #L83 - L84 were not covered by tests
}
Err(e) => {
error!("Cannot read {relative_path:?}: {e:?}");
Expand All @@ -95,9 +106,10 @@
}
}

pub fn create_dataset(config: &[RepositoryConfig]) -> Result<()> {
pub fn create_dataset(config: &[RepositoryConfig], access: &impl RepositoryAccess) -> Result<()> {

Check warning on line 109 in crates/tabby-scheduler/src/dataset.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/dataset.rs#L109

Added line #L109 was not covered by tests
fs::remove_dir_all(dataset_dir()).ok();
fs::create_dir_all(dataset_dir())?;

let mut writer = FileRotate::new(
SourceFile::files_jsonl(),
AppendCount::new(usize::max_value()),
Expand All @@ -107,15 +119,21 @@
None,
);

let snapshot_version = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Failed to read system clock")
.as_millis() as u64;
access.start_snapshot(snapshot_version);

Check warning on line 126 in crates/tabby-scheduler/src/dataset.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/dataset.rs#L122-L126

Added lines #L122 - L126 were not covered by tests
let mut deps = DependencyFile::default();
for repository in config {
deps::collect(repository.dir().as_path(), &mut deps);
repository.create_dataset(&mut writer)?;
repository.create_dataset(&mut writer, access, snapshot_version.clone())?;

Check warning on line 130 in crates/tabby-scheduler/src/dataset.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/dataset.rs#L130

Added line #L130 was not covered by tests
}

serdeconv::to_json_file(&deps, dependency_file())?;

writer.flush()?;
access.finish_snapshot(snapshot_version);

Check warning on line 136 in crates/tabby-scheduler/src/dataset.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/dataset.rs#L136

Added line #L136 was not covered by tests
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pub async fn scheduler<T: RepositoryAccess + 'static>(now: bool, access: T) -> Result<()> {
if now {
let repositories = access.list_repositories().await?;
job_sync(&repositories)?;
job_sync(&repositories, &access)?;

Check warning on line 18 in crates/tabby-scheduler/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/lib.rs#L18

Added line #L18 was not covered by tests
job_index(&repositories)?;
} else {
let access = Arc::new(access);
Expand All @@ -37,7 +37,7 @@
.list_repositories()
.await
.expect("Must be able to retrieve repositories for sync");
if let Err(e) = job_sync(&repositories) {
if let Err(e) = job_sync(&repositories, &*access) {

Check warning on line 40 in crates/tabby-scheduler/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/lib.rs#L40

Added line #L40 was not covered by tests
error!("{e}");
}
if let Err(e) = job_index(&repositories) {
Expand Down Expand Up @@ -66,15 +66,15 @@
Ok(())
}

fn job_sync(repositories: &[RepositoryConfig]) -> Result<()> {
fn job_sync(repositories: &[RepositoryConfig], access: &impl RepositoryAccess) -> Result<()> {

Check warning on line 69 in crates/tabby-scheduler/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/lib.rs#L69

Added line #L69 was not covered by tests
println!("Syncing {} repositories...", repositories.len());
let ret = repository::sync_repositories(repositories);
if let Err(err) = ret {
return Err(err.context("Failed to sync repositories"));
}

println!("Building dataset...");
let ret = dataset::create_dataset(repositories);
let ret = dataset::create_dataset(repositories, access);

Check warning on line 77 in crates/tabby-scheduler/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/lib.rs#L77

Added line #L77 was not covered by tests
if let Err(err) = ret {
return Err(err.context("Failed to build dataset"));
}
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-webserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hyper = { workspace = true, features = ["client"] }
jsonwebtoken = "9.1.0"
juniper.workspace = true
juniper-axum = { path = "../../crates/juniper-axum" }
kv = { version = "0.24.0", features = ["json-value"] }
lazy_static.workspace = true
lettre = { version = "0.11.3", features = ["tokio1", "tokio1-native-tls"] }
mime_guess = "2.0.4"
Expand Down
Loading
Loading