diff --git a/sync_service.py b/sync_service.py index 3ef1284..73f8a09 100644 --- a/sync_service.py +++ b/sync_service.py @@ -556,9 +556,24 @@ class SyncService: def close(self): """Close connections for this data source""" - self.stop_auto_sync() + # 先设置停止标志,防止新同步开始 + self._running = False + self._sync_in_progress = False + + # 取消自动同步任务 + if hasattr(self, '_auto_sync_task') and self._auto_sync_task is not None and not self._auto_sync_task.done(): + try: + self._auto_sync_task.cancel() + except Exception as e: + logger.error(f"Error cancelling auto sync task: {e}") + + # 停止当前同步 + self._sync_in_progress = False + if hasattr(self.syncer, 'close'): self.syncer.close() + + logger.info(f"Closed all connections for {self.source_name}") class SyncServiceManager: