@@ -2,11 +2,7 @@ cfg_core! {
2
2
use crate :: EncryptionConfig ;
3
3
}
4
4
5
- use std:: sync:: Arc ;
6
-
7
- use tracing:: Instrument as _;
8
-
9
- use crate :: { sync:: DropAbort , Database , Result } ;
5
+ use crate :: { Database , Result } ;
10
6
11
7
use super :: DbType ;
12
8
@@ -600,6 +596,8 @@ cfg_sync! {
600
596
601
597
/// Build a connection to a local database that can be synced to remote server.
602
598
pub async fn build( self ) -> Result <Database > {
599
+ use tracing:: Instrument as _;
600
+
603
601
let SyncedDatabase {
604
602
path,
605
603
flags,
@@ -645,7 +643,7 @@ cfg_sync! {
645
643
db. sync_ctx. as_ref( ) . unwrap( ) . lock( ) . await . set_push_batch_size( push_batch_size) ;
646
644
}
647
645
648
- let mut bg_abort: Option <Arc <DropAbort >> = None ;
646
+ let mut bg_abort: Option <std :: sync :: Arc <crate :: sync :: DropAbort >> = None ;
649
647
let conn = db. connect( ) ?;
650
648
651
649
let sync_ctx = db. sync_ctx. as_ref( ) . unwrap( ) . clone( ) ;
@@ -656,17 +654,22 @@ cfg_sync! {
656
654
loop {
657
655
tracing:: trace!( "trying to sync" ) ;
658
656
let mut ctx = sync_ctx. lock( ) . await ;
659
- if let Err ( e) = crate :: sync:: try_pull( & mut ctx, & conn) . await {
660
- tracing:: error!( "sync error: {}" , e) ;
657
+ if remote_writes {
658
+ if let Err ( e) = crate :: sync:: try_pull( & mut ctx, & conn) . await {
659
+ tracing:: error!( "sync error: {}" , e) ;
660
+ }
661
+ } else {
662
+ if let Err ( e) = crate :: sync:: sync_offline( & mut ctx, & conn) . await {
663
+ tracing:: error!( "sync error: {}" , e) ;
664
+ }
661
665
}
662
-
663
666
tokio:: time:: sleep( sync_interval) . await ;
664
667
}
665
668
}
666
669
. instrument( tracing:: info_span!( "sync_interval" ) ) ,
667
670
) ;
668
671
669
- bg_abort. replace( Arc :: new( DropAbort ( jh. abort_handle( ) ) ) ) ;
672
+ bg_abort. replace( std :: sync :: Arc :: new( crate :: sync :: DropAbort ( jh. abort_handle( ) ) ) ) ;
670
673
}
671
674
672
675
Ok ( Database {
0 commit comments