refactor(build): reformat code and add tonic health dependency
- Reformatted build script with proper indentation and line breaks - Added tonic-health dependency to Cargo.toml and updated lock file - Improved error handling in disk cache with concurrent deletion checks - Refactored conditional chains using && and let expressions - Reformatted struct initialization and function parameter lists - Added proper spacing and alignment in language stats processing - Improved assertion formatting in test cases - Reorganized import statements and code layout in multiple files - Updated metrics functions with better parameter handling and formatting
This commit is contained in:
@@ -59,48 +59,50 @@ fn init_tracing() -> Option<tracing_appender::non_blocking::WorkerGuard> {
|
||||
|
||||
// Optional file output with rotation
|
||||
if let Ok(log_dir) = std::env::var("GITKS_LOG_DIR") {
|
||||
let rotation = match env_or("GITKS_LOG_ROTATION", "daily").as_str() {
|
||||
"hourly" => tracing_appender::rolling::Rotation::HOURLY,
|
||||
"never" => tracing_appender::rolling::Rotation::NEVER,
|
||||
_ => tracing_appender::rolling::Rotation::DAILY,
|
||||
};
|
||||
let retention = env_u64("GITKS_LOG_RETENTION", 7) as usize;
|
||||
let rotation = match env_or("GITKS_LOG_ROTATION", "daily").as_str() {
|
||||
"hourly" => tracing_appender::rolling::Rotation::HOURLY,
|
||||
"never" => tracing_appender::rolling::Rotation::NEVER,
|
||||
_ => tracing_appender::rolling::Rotation::DAILY,
|
||||
};
|
||||
let retention = env_u64("GITKS_LOG_RETENTION", 7) as usize;
|
||||
|
||||
let mut builder = tracing_appender::rolling::Builder::new()
|
||||
.rotation(rotation)
|
||||
.filename_prefix("gitks")
|
||||
.filename_suffix("log");
|
||||
let mut builder = tracing_appender::rolling::Builder::new()
|
||||
.rotation(rotation)
|
||||
.filename_prefix("gitks")
|
||||
.filename_suffix("log");
|
||||
|
||||
if retention > 0 {
|
||||
builder = builder.max_log_files(retention);
|
||||
}
|
||||
|
||||
let file_appender = builder.build(&log_dir).expect("failed to create log directory");
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
let file_layer = fmt::layer()
|
||||
.json()
|
||||
.with_target(true)
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.with_writer(non_blocking)
|
||||
.with_filter(EnvFilter::new("info"))
|
||||
.boxed();
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(env_filter)
|
||||
.with(fmt_layer)
|
||||
.with(file_layer)
|
||||
.init();
|
||||
|
||||
Some(guard)
|
||||
} else {
|
||||
tracing_subscriber::registry()
|
||||
.with(env_filter)
|
||||
.with(fmt_layer)
|
||||
.init();
|
||||
None
|
||||
if retention > 0 {
|
||||
builder = builder.max_log_files(retention);
|
||||
}
|
||||
|
||||
let file_appender = builder
|
||||
.build(&log_dir)
|
||||
.expect("failed to create log directory");
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
let file_layer = fmt::layer()
|
||||
.json()
|
||||
.with_target(true)
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.with_writer(non_blocking)
|
||||
.with_filter(EnvFilter::new("info"))
|
||||
.boxed();
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(env_filter)
|
||||
.with(fmt_layer)
|
||||
.with(file_layer)
|
||||
.init();
|
||||
|
||||
Some(guard)
|
||||
} else {
|
||||
tracing_subscriber::registry()
|
||||
.with(env_filter)
|
||||
.with(fmt_layer)
|
||||
.init();
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -143,10 +145,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
|
||||
if disk_cache_enabled {
|
||||
tracing::info!(
|
||||
max_age_secs = disk_cache_max_age,
|
||||
"disk cache enabled"
|
||||
);
|
||||
tracing::info!(max_age_secs = disk_cache_max_age, "disk cache enabled");
|
||||
disk_cache.cleanup_on_startup()?;
|
||||
gitks::disk_cache::start_cache_cleanup_task(disk_cache.clone(), Duration::from_secs(300));
|
||||
} else {
|
||||
@@ -290,8 +289,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
let raft_data_dir = repo_prefix.join(".gitks_raft");
|
||||
let (node_actor, node_handle) =
|
||||
init_actor_cluster(svc.clone(), storage_name.clone(), grpc_addr.clone(), raft_data_dir).await?;
|
||||
let (node_actor, node_handle) = init_actor_cluster(
|
||||
svc.clone(),
|
||||
storage_name.clone(),
|
||||
grpc_addr.clone(),
|
||||
raft_data_dir,
|
||||
)
|
||||
.await?;
|
||||
let svc = svc
|
||||
.with_actor(node_actor.clone())
|
||||
.with_grpc_addr(grpc_addr.clone());
|
||||
|
||||
Reference in New Issue
Block a user