Skip to content

Commit

Permalink
feat(3133 ): suggest users to update the rc files if it's are not upd…
Browse files Browse the repository at this point in the history
…ated (#3136)
  • Loading branch information
dekkku authored Nov 22, 2024
1 parent 8ee2046 commit 847d1da
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cli/tc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mod helpers;
mod init;
pub mod run;
mod start;
mod validate_rc;
5 changes: 4 additions & 1 deletion src/cli/tc/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::Parser;
use dotenvy::dotenv;

use super::helpers::TRACKER;
use super::validate_rc::validate_rc_config_files;
use super::{check, gen, init, start};
use crate::cli::command::{Cli, Command};
use crate::cli::{self, update_checker};
Expand Down Expand Up @@ -41,11 +42,13 @@ fn get_runtime_and_config_reader(verify_ssl: bool) -> (TargetRuntime, ConfigRead
async fn run_command(cli: Cli) -> Result<()> {
match cli.command {
Command::Start { file_paths, verify_ssl } => {
let (_, config_reader) = get_runtime_and_config_reader(verify_ssl);
let (runtime, config_reader) = get_runtime_and_config_reader(verify_ssl);
validate_rc_config_files(runtime, &file_paths).await;
start::start_command(file_paths, &config_reader).await?;
}
Command::Check { file_paths, n_plus_one_queries, schema, format, verify_ssl } => {
let (runtime, config_reader) = get_runtime_and_config_reader(verify_ssl);
validate_rc_config_files(runtime.clone(), &file_paths).await;
check::check_command(
check::CheckParams { file_paths, n_plus_one_queries, schema, format, runtime },
&config_reader,
Expand Down
49 changes: 49 additions & 0 deletions src/cli/tc/validate_rc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::path::Path;

use super::helpers::{TAILCALL_RC, TAILCALL_RC_SCHEMA};
use crate::core::runtime::TargetRuntime;

pub async fn validate_rc_config_files(runtime: TargetRuntime, file_paths: &[String]) {
// base config files.
let tailcallrc = include_str!("../../../generated/.tailcallrc.graphql");
let tailcallrc_json = include_str!("../../../generated/.tailcallrc.schema.json");

// Define the config files to check with their base contents
let rc_config_files = vec![
(TAILCALL_RC, tailcallrc),
(TAILCALL_RC_SCHEMA, tailcallrc_json),
];

for path in file_paths {
let parent_dir = match Path::new(path).parent() {
Some(dir) => dir,
None => continue,
};

let mut outdated_files = Vec::with_capacity(rc_config_files.len());

for (file_name, base_content) in &rc_config_files {
let config_path = parent_dir.join(file_name);
if config_path.exists() {
if let Ok(content) = runtime.file.read(&config_path.to_string_lossy()).await {
if &content != base_content {
// file content not same.
outdated_files.push(file_name.to_owned());
}
} else {
// unable to read file.
outdated_files.push(file_name.to_owned());
}
}
}

if !outdated_files.is_empty() {
let outdated_files = outdated_files.join(", ");
tracing::warn!(
"[{}] {} outdated, reinitialize using tailcall init.",
outdated_files,
pluralizer::pluralize("is", outdated_files.len() as isize, false)
);
}
}
}

1 comment on commit 847d1da

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 4.11ms 1.88ms 30.28ms 76.65%
Req/Sec 6.21k 767.15 8.06k 94.50%

741218 requests in 30.02s, 3.72GB read

Requests/sec: 24692.02

Transfer/sec: 126.74MB

Please sign in to comment.