@@ -777,6 +777,15 @@ pub(crate) async fn sync_task(
777777 let site_path = site_path. clone ( ) ;
778778 let app_state = app_state. clone ( ) ;
779779 let logger_tx = logger_tx. clone ( ) ;
780+
781+ fn send_trim ( site_path : String , dirtylog_cmd_tx : UnboundedSender < DirtyLogCommand > ) {
782+ if let Err ( e) = dirtylog_cmd_tx. unbounded_send ( DirtyLogCommand :: Trim { site : site_path } ) {
783+ let err_msg = e. to_string ( ) ;
784+ let command = e. into_inner ( ) ;
785+ log:: error!( "Cannot send dirtylog Trim command {command:?}: {err_msg}" )
786+ }
787+ }
788+
780789 match sub_hp {
781790 SubHpInfo :: Normal { sync_path, download_chunk_size } => {
782791 let site_suffix = shvrpc:: util:: strip_prefix_path ( & site_path, & site_info. sub_hp )
@@ -787,7 +796,7 @@ pub(crate) async fn sync_task(
787796 let sync_task = tokio:: spawn ( async move {
788797 let sync_logger = SyncSiteLogger :: new ( & site_path, logger_tx) ;
789798 let sync_result = sync_site_by_download (
790- site_path,
799+ site_path. clone ( ) ,
791800 remote_journal_path,
792801 download_chunk_size,
793802 client_cmd_tx,
@@ -799,6 +808,7 @@ pub(crate) async fn sync_task(
799808 sync_logger. log ( log:: Level :: Error , format ! ( "site sync error: {err}" ) ) ;
800809 }
801810 sync_logger. log ( log:: Level :: Info , "syncing done" ) ;
811+ send_trim ( site_path, app_state. dirtylog_cmd_tx . clone ( ) ) ;
802812 drop ( permit) ;
803813 } ) ;
804814 sync_tasks. push ( sync_task) ;
@@ -810,7 +820,7 @@ pub(crate) async fn sync_task(
810820 let sync_task = tokio:: spawn ( async move {
811821 let sync_logger = SyncSiteLogger :: new ( & site_path, logger_tx) ;
812822 let sync_result = sync_site_legacy (
813- site_path,
823+ site_path. clone ( ) ,
814824 remote_getlog_path,
815825 client_cmd_tx,
816826 & app_state. config . journal_dir ,
@@ -820,6 +830,7 @@ pub(crate) async fn sync_task(
820830 sync_logger. log ( log:: Level :: Error , format ! ( "site sync error: {err}" ) ) ;
821831 }
822832 sync_logger. log ( log:: Level :: Info , "syncing done" ) ;
833+ send_trim ( site_path, app_state. dirtylog_cmd_tx . clone ( ) ) ;
823834 drop ( permit) ;
824835 } ) ;
825836 sync_tasks. push ( sync_task) ;
@@ -831,14 +842,6 @@ pub(crate) async fn sync_task(
831842 }
832843 futures:: future:: join_all ( sync_tasks) . await ;
833844 log:: info!( "Sync logs done in {} s" , sync_start. elapsed( ) . as_secs( ) ) ;
834- sites_to_trim
835- . into_iter ( )
836- . for_each ( |site|
837- app_state. dirtylog_cmd_tx . unbounded_send ( DirtyLogCommand :: Trim { site : site. clone ( ) } )
838- . unwrap_or_else ( |e|
839- log:: error!( "Cannot send dirtylog Trim command for site {site}: {e}" )
840- )
841- ) ;
842845 match cleanup_log_files ( & app_state. config . journal_dir , max_journal_dir_size, days_to_keep) . await {
843846 Ok ( _) => info ! ( "Cleanup journal dir done" ) ,
844847 Err ( err) => error ! ( "Cleanup journal dir error: {err}" ) ,
0 commit comments