Skip to content

Commit 0660fa7

Browse files
Merge pull request #247 from code0-tech/246-remove-watcher-from-push
Removed Watcher From Push Command
2 parents 22280f0 + bbf3c62 commit 0660fa7

4 files changed

Lines changed: 56 additions & 132 deletions

File tree

crates/cli/src/command/push/data_type_client_impl.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::command::push::auth::get_authorization_metadata;
2+
use crate::formatter::{error_without_trace, info};
23
use tonic::{Extensions, Request, transport::Channel};
34
use tucana::sagittarius::{
45
DataTypeUpdateRequest as SagittariusDataTypeUpdateRequest,
@@ -15,7 +16,9 @@ impl SagittariusDataTypeServiceClient {
1516
pub async fn new(sagittarius_url: String, token: String) -> Self {
1617
let client = match DataTypeServiceClient::connect(sagittarius_url).await {
1718
Ok(client) => {
18-
log::info!("Successfully connected to Sagittarius DataType Endpoint!");
19+
info(String::from(
20+
"Successfully connected to Sagittarius DataType Endpoint!",
21+
));
1922
client
2023
}
2124
Err(err) => panic!(
@@ -36,13 +39,13 @@ impl SagittariusDataTypeServiceClient {
3639

3740
match self.client.update(request).await {
3841
Ok(response) => {
39-
log::info!(
42+
info(format!(
4043
"Successfully transferred data types. Did Sagittarius updated them? {:?}",
41-
&response
42-
);
44+
&response.into_inner().success
45+
));
4346
}
4447
Err(err) => {
45-
log::error!("Failed to update DataTypes: {:?}", err);
48+
error_without_trace(format!("Failed to update DataTypes: {:?}", err));
4649
}
4750
};
4851
}

crates/cli/src/command/push/flow_type_client_impl.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::command::push::auth::get_authorization_metadata;
2+
use crate::formatter::error_without_trace;
3+
use crate::formatter::info;
24
use tonic::Extensions;
35
use tonic::Request;
46
use tonic::transport::Channel;
@@ -15,7 +17,9 @@ impl SagittariusFlowTypeServiceClient {
1517
pub async fn new(sagittarius_url: String, token: String) -> Self {
1618
let client = match FlowTypeServiceClient::connect(sagittarius_url).await {
1719
Ok(client) => {
18-
log::info!("Successfully connected to Sagittarius FlowType Endpoint!");
20+
info(String::from(
21+
"Successfully connected to Sagittarius FlowType Endpoint!",
22+
));
1923
client
2024
}
2125
Err(err) => panic!(
@@ -36,13 +40,13 @@ impl SagittariusFlowTypeServiceClient {
3640

3741
match self.client.update(request).await {
3842
Ok(response) => {
39-
log::info!(
43+
info(format!(
4044
"Successfully transferred FlowTypes. Did Sagittarius updated them? {:?}",
41-
&response
42-
);
45+
&response.into_inner().success
46+
));
4347
}
4448
Err(err) => {
45-
log::error!("Failed to update FlowTypes: {:?}", err);
49+
error_without_trace(format!("Failed to update FlowTypes: {:?}", err));
4650
}
4751
};
4852
}

crates/cli/src/command/push/function_client_impl.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::command::push::auth::get_authorization_metadata;
2+
use crate::formatter::error_without_trace;
3+
use crate::formatter::info;
24
use tonic::Extensions;
35
use tonic::Request;
46
use tonic::transport::Channel;
@@ -15,7 +17,9 @@ impl SagittariusRuntimeFunctionServiceClient {
1517
pub async fn new(sagittarius_url: String, token: String) -> Self {
1618
let client = match RuntimeFunctionDefinitionServiceClient::connect(sagittarius_url).await {
1719
Ok(client) => {
18-
log::info!("Successfully connected to Sagittarius RuntimeFunction Endpoint!");
20+
info(String::from(
21+
"Successfully connected to Sagittarius RuntimeFunction Endpoint!",
22+
));
1923
client
2024
}
2125
Err(err) => panic!(
@@ -39,13 +43,13 @@ impl SagittariusRuntimeFunctionServiceClient {
3943

4044
match self.client.update(request).await {
4145
Ok(response) => {
42-
log::info!(
46+
info(format!(
4347
"Successfully transferred RuntimeFunctions. Did Sagittarius updated them? {:?}",
44-
&response
45-
);
48+
&response.into_inner().success
49+
));
4650
}
4751
Err(err) => {
48-
log::error!("Failed to update RuntimeFunctions: {:?}", err);
52+
error_without_trace(format!("Failed to update RuntimeFunctions: {:?}", err));
4953
}
5054
};
5155
}

crates/cli/src/command/push/mod.rs

Lines changed: 30 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ use crate::analyser::core::Analyser;
22
use crate::command::push::data_type_client_impl::SagittariusDataTypeServiceClient;
33
use crate::command::push::flow_type_client_impl::SagittariusFlowTypeServiceClient;
44
use crate::command::push::function_client_impl::SagittariusRuntimeFunctionServiceClient;
5-
use crate::formatter::{default, info};
6-
use notify::event::ModifyKind;
7-
use notify::{EventKind, RecursiveMode, Watcher, recommended_watcher};
8-
use std::sync::mpsc::channel;
9-
use std::time::{Duration, Instant};
105

116
mod auth;
127
mod data_type_client_impl;
@@ -16,122 +11,40 @@ mod function_client_impl;
1611
pub async fn push(token: String, url: String, path: Option<String>) {
1712
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
1813

19-
info(format!("Watching directory: {dir_path}"));
20-
info(String::from("Press Ctrl+C to stop watching..."));
21-
22-
{
23-
Analyser::new(dir_path.as_str()).report(false, true);
24-
}
25-
26-
// Set up file watcher
27-
let (tx, rx) = channel();
28-
let mut watcher = recommended_watcher(tx).unwrap();
29-
watcher
30-
.watch(std::path::Path::new(&dir_path), RecursiveMode::Recursive)
31-
.unwrap();
32-
33-
let mut last_run = Instant::now();
34-
14+
let mut analyzer = Analyser::new(dir_path.as_str());
3515
let mut data_type_client =
3616
SagittariusDataTypeServiceClient::new(url.clone(), token.clone()).await;
3717
let mut flow_type_client =
3818
SagittariusFlowTypeServiceClient::new(url.clone(), token.clone()).await;
3919
let mut function_client = SagittariusRuntimeFunctionServiceClient::new(url, token).await;
4020

41-
loop {
42-
if let Ok(Ok(event)) = rx.recv() {
43-
match event.kind {
44-
EventKind::Modify(modify) => {
45-
if let ModifyKind::Data(_) = modify
46-
&& last_run.elapsed() > Duration::from_millis(500)
47-
{
48-
default(String::from(
49-
"\n\n\n--------------------------------------------------------------------------\n\n",
50-
));
51-
info(String::from("Change detected! Regenerating report..."));
52-
let mut analyzer = Analyser::new(dir_path.as_str());
53-
54-
// No errors when reporter is empty!
55-
if analyzer.reporter.is_empty() {
56-
data_type_client
57-
.update_data_types(
58-
analyzer
59-
.data_types
60-
.iter()
61-
.map(|d| d.definition_data_type.clone())
62-
.collect(),
63-
)
64-
.await;
65-
flow_type_client
66-
.update_flow_types(
67-
analyzer
68-
.flow_types
69-
.iter()
70-
.map(|d| d.flow_type.clone())
71-
.collect(),
72-
)
73-
.await;
74-
function_client
75-
.update_runtime_function_definitions(
76-
analyzer
77-
.functions
78-
.iter()
79-
.map(|d| d.function.clone())
80-
.collect(),
81-
)
82-
.await;
83-
}
84-
85-
analyzer.report(false, true);
86-
87-
last_run = Instant::now();
88-
}
89-
}
90-
EventKind::Remove(_) => {
91-
if last_run.elapsed() > Duration::from_millis(500) {
92-
default(String::from(
93-
"\n\n\n--------------------------------------------------------------------------\n\n",
94-
));
95-
info(String::from("Change detected! Regenerating report..."));
96-
let mut analyzer = Analyser::new(dir_path.as_str());
97-
98-
// No errors when reporter is empty!
99-
if analyzer.reporter.is_empty() {
100-
data_type_client
101-
.update_data_types(
102-
analyzer
103-
.data_types
104-
.iter()
105-
.map(|d| d.definition_data_type.clone())
106-
.collect(),
107-
)
108-
.await;
109-
flow_type_client
110-
.update_flow_types(
111-
analyzer
112-
.flow_types
113-
.iter()
114-
.map(|d| d.flow_type.clone())
115-
.collect(),
116-
)
117-
.await;
118-
function_client
119-
.update_runtime_function_definitions(
120-
analyzer
121-
.functions
122-
.iter()
123-
.map(|d| d.function.clone())
124-
.collect(),
125-
)
126-
.await;
127-
}
128-
129-
analyzer.report(false, true);
130-
last_run = Instant::now();
131-
}
132-
}
133-
_ => {}
134-
}
135-
}
136-
}
21+
analyzer.report(false, true);
22+
23+
data_type_client
24+
.update_data_types(
25+
analyzer
26+
.data_types
27+
.iter()
28+
.map(|d| d.definition_data_type.clone())
29+
.collect(),
30+
)
31+
.await;
32+
flow_type_client
33+
.update_flow_types(
34+
analyzer
35+
.flow_types
36+
.iter()
37+
.map(|d| d.flow_type.clone())
38+
.collect(),
39+
)
40+
.await;
41+
function_client
42+
.update_runtime_function_definitions(
43+
analyzer
44+
.functions
45+
.iter()
46+
.map(|d| d.function.clone())
47+
.collect(),
48+
)
49+
.await;
13750
}

0 commit comments

Comments
 (0)