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(2688): --watch for changes #2707

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6932843
feat: watch changes in path
beelchester Aug 15, 2024
0abc74b
revert comment
beelchester Aug 15, 2024
9645c38
remove outer task
beelchester Aug 15, 2024
a532348
use config_error flag and content event for notify
beelchester Aug 15, 2024
63fe1c2
refact: start_watch_server
beelchester Aug 15, 2024
15c40b9
optimize server in watch mode
beelchester Aug 17, 2024
1879460
remove separate watch task
beelchester Aug 17, 2024
02f0b23
watch for linked files also and add debounce delay
beelchester Aug 17, 2024
1233dea
fix: first server run sometimes fails
beelchester Aug 17, 2024
4b9dd5f
fix: add delay to let server stop
beelchester Aug 17, 2024
75cd209
update command description
beelchester Aug 17, 2024
19f53f0
increase init last_event_time
beelchester Aug 17, 2024
a27bbda
fix: build
beelchester Aug 17, 2024
fe7c562
fix server and handle relative link paths
beelchester Aug 23, 2024
c53458c
fix: lint
beelchester Aug 23, 2024
d61e32d
Merge branch 'main' into feat/watch-path
beelchester Aug 23, 2024
c1409b3
use arc_config_reader in start
beelchester Aug 23, 2024
15891ba
fix: build
beelchester Aug 23, 2024
aa6d9cc
Merge branch 'main' into feat/watch-path
tusharmath Aug 26, 2024
1db8662
prevent logs on restart in watch mode
beelchester Aug 26, 2024
70ad866
fix: errors not showing on first run
beelchester Aug 31, 2024
631420c
Merge branch 'main' into feat/watch-path
beelchester Aug 31, 2024
cd40bec
fix: lint
beelchester Aug 31, 2024
354d2b7
drop prevent logs
tusharmath Sep 1, 2024
efc9515
Merge branch 'main' into feat/watch-path
beelchester Sep 8, 2024
61f37a7
Merge branch 'main' into feat/watch-path
beelchester Sep 15, 2024
d8d89c4
Merge branch 'main' into feat/watch-path
beelchester Sep 24, 2024
34b17b6
Merge branch 'main' into feat/watch-path
beelchester Sep 29, 2024
0007f39
Merge branch 'main' into feat/watch-path
beelchester Oct 9, 2024
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
82 changes: 82 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ num = "0.4.3"
indenter = "0.3.3"
derive_more = { workspace = true }
strum = "0.26.2"
notify = "6.1.1"

[dev-dependencies]
datatest-stable = "0.2.9"
Expand Down
3 changes: 3 additions & 0 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
/// separated by spaces if more than one
#[arg(required = true)]
file_paths: Vec<String>,
/// Watch for file changes
#[arg(short, long)]
watch: bool,

Check warning on line 31 in src/cli/command.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/command.rs#L31

Added line #L31 was not covered by tests
},

/// Validate a composition spec
Expand Down
24 changes: 17 additions & 7 deletions src/cli/server/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::ops::Deref;
use std::sync::Arc;
use std::sync::{Arc, Mutex};

use anyhow::Result;
use lazy_static::lazy_static;
use tokio::runtime::Runtime;
use tokio::sync::oneshot::{self};

use super::http_1::start_http_1;
Expand All @@ -12,6 +14,10 @@
use crate::core::config::ConfigModule;
use crate::core::Errata;

lazy_static! {
pub static ref RUNTIME: Arc<Mutex<Option<Runtime>>> = Arc::new(Mutex::new(None));
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the runtime into the server. Let's not create static runtimes this way.

}

pub struct Server {
config_module: ConfigModule,
server_up_sender: Option<oneshot::Sender<()>>,
Expand Down Expand Up @@ -47,15 +53,19 @@
}

/// Starts the server in its own multithreaded Runtime
pub async fn fork_start(self) -> Result<()> {
pub async fn fork_start(self, watch: bool) -> Result<()> {

Check warning on line 56 in src/cli/server/http_server.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_server.rs#L56

Added line #L56 was not covered by tests
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(self.config_module.deref().server.get_workers())
.enable_all()
.build()?;

let result = runtime.spawn(async { self.start().await }).await?;
runtime.shutdown_background();

result
if watch {
let handle = runtime.spawn(async { self.start().await });
RUNTIME.lock().unwrap().get_or_insert(runtime);
handle.await?

Check warning on line 64 in src/cli/server/http_server.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_server.rs#L61-L64

Added lines #L61 - L64 were not covered by tests
} else {
let result = runtime.spawn(async { self.start().await }).await?;
runtime.shutdown_background();
result

Check warning on line 68 in src/cli/server/http_server.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_server.rs#L66-L68

Added lines #L66 - L68 were not covered by tests
}
}
}
2 changes: 1 addition & 1 deletion src/cli/tc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ mod gen;
mod helpers;
mod init;
pub mod run;
mod start;
pub mod start;
4 changes: 2 additions & 2 deletions src/cli/tc/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

async fn run_command(cli: Cli, config_reader: ConfigReader, runtime: TargetRuntime) -> Result<()> {
match cli.command {
Command::Start { file_paths } => {
start::start_command(file_paths, &config_reader).await?;
Command::Start { file_paths, watch } => {
start::start_command(file_paths, watch, config_reader).await?;

Check warning on line 39 in src/cli/tc/run.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/run.rs#L38-L39

Added lines #L38 - L39 were not covered by tests
}
Command::Check { file_paths, n_plus_one_queries, schema, format } => {
check::check_command(
Expand Down
Loading
Loading