@@ -2,11 +2,6 @@ use crate::analyser::core::Analyser;
22use crate :: command:: push:: data_type_client_impl:: SagittariusDataTypeServiceClient ;
33use crate :: command:: push:: flow_type_client_impl:: SagittariusFlowTypeServiceClient ;
44use 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
116mod auth;
127mod data_type_client_impl;
@@ -16,122 +11,40 @@ mod function_client_impl;
1611pub 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