From 441fdddf2632d5d6577a1a5420e1a34687a992bd Mon Sep 17 00:00:00 2001 From: milkfish Date: Tue, 28 Oct 2025 15:34:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20syncFiles=20?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E9=99=90=E5=88=B6=E4=B8=8E=E7=AD=89=E5=BE=85?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=85=A8=E9=83=A8=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/service/ClusterService.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt b/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt index 95a6fed..79e69be 100644 --- a/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt +++ b/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt @@ -28,6 +28,7 @@ import io.socket.client.Socket import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withPermit import kotlinx.serialization.decodeFromByteArray @@ -92,19 +93,21 @@ class ClusterService( val sema = Semaphore(syncConfig.concurrency) - missingFiles.forEach { file -> - sema.withPermit { - async { - try { - downloadFile(file) - logger.debug { "Downloaded: ${file.path}" } - } catch (e: Exception) { - logger.error(e) { "Failed to download ${file.path}" } - throw e - } - } - } - } + val jobs = missingFiles.map { file -> + async { + sema.withPermit { + try { + downloadFile(file) + logger.debug { "Downloaded: ${file.path}" } + } catch (e: Exception) { + logger.error(e) { "Failed to download ${file.path}" } + throw e + } + } + } + } + + jobs.awaitAll() logger.info { "Sync completed: ${missingFiles.size} files" } } From 1bdbb903a83165b17b646023eedfcb67ac5419a2 Mon Sep 17 00:00:00 2001 From: milkfish Date: Wed, 29 Oct 2025 11:54:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=B0=86=E5=88=B6=E8=A1=A8=E7=AC=A6?= =?UTF-8?q?=E7=BC=A9=E8=BF=9B=E6=94=B9=E4=B8=BA4=E4=B8=AA=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=EF=BC=8C=E4=B8=8E=E5=85=B6=E4=BB=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/service/ClusterService.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt b/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt index 79e69be..7c8e6ee 100644 --- a/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt +++ b/src/main/kotlin/com/bangbang93/openbmclapi/agent/service/ClusterService.kt @@ -93,21 +93,21 @@ class ClusterService( val sema = Semaphore(syncConfig.concurrency) - val jobs = missingFiles.map { file -> - async { - sema.withPermit { - try { - downloadFile(file) - logger.debug { "Downloaded: ${file.path}" } - } catch (e: Exception) { - logger.error(e) { "Failed to download ${file.path}" } - throw e - } - } - } - } - - jobs.awaitAll() + val jobs = missingFiles.map { file -> + async { + sema.withPermit { + try { + downloadFile(file) + logger.debug { "Downloaded: ${file.path}" } + } catch (e: Exception) { + logger.error(e) { "Failed to download ${file.path}" } + throw e + } + } + } + } + + jobs.awaitAll() logger.info { "Sync completed: ${missingFiles.size} files" } }