File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @sql-controller/cli " : patch
3+ ---
4+
5+ Retry sync
Original file line number Diff line number Diff line change @@ -35,16 +35,26 @@ export default async function start(options: {
3535 configPath : string ;
3636} ) {
3737 let lastConfig : Config ;
38-
39- console . info ( grey ( "Syncing..." ) ) ;
38+ let syncing = false ;
39+ let synced = false ;
4040
4141 const safeSync = async ( ) => {
42+ syncing = true ;
43+ console . info ( grey ( "Syncing..." ) ) ;
4244 try {
4345 const [ result , config ] = await run ( options , lastConfig ) ;
4446 lastConfig = config ;
45- if ( ! result ?. exitCode ) console . info ( green ( "Synced successfully" ) ) ;
47+ if ( ! result ?. exitCode ) {
48+ synced = true ;
49+ console . info ( green ( "Synced successfully" ) ) ;
50+ } else {
51+ synced = false ;
52+ }
4653 } catch ( error ) {
54+ synced = false ;
4755 console . error ( red ( error ) ) ;
56+ } finally {
57+ syncing = false ;
4858 }
4959 } ;
5060
@@ -57,7 +67,15 @@ export default async function start(options: {
5767 usePolling : true ,
5868 } ) ;
5969
60- return new Promise ( ( resolve , reject ) =>
61- watcher . on ( "error" , reject ) . on ( "all" , safeSync )
62- ) ;
70+ const interval = setInterval ( async ( ) => {
71+ if ( ! syncing && ! synced ) await safeSync ( ) ;
72+ } , 30_000 ) ;
73+
74+ try {
75+ await new Promise ( ( resolve , reject ) =>
76+ watcher . on ( "error" , reject ) . on ( "all" , safeSync )
77+ ) ;
78+ } finally {
79+ clearInterval ( interval ) ;
80+ }
6381}
You can’t perform that action at this time.
0 commit comments