@@ -3,18 +3,16 @@ package com.saveourtool.common.storage
33import com.saveourtool.common.utils.getLogger
44import com.saveourtool.common.utils.info
55import com.saveourtool.common.utils.isNotNull
6- import io.ktor.client.utils.*
7-
86import org.slf4j.Logger
97import reactor.core.publisher.Mono
108import reactor.core.scheduler.Scheduler
119import reactor.core.scheduler.Schedulers
12-
1310import java.util.concurrent.atomic.AtomicBoolean
1411import java.util.concurrent.atomic.AtomicInteger
15-
1612import kotlin.reflect.KClass
17- import kotlinx.coroutines.*
13+ import kotlinx.coroutines.CoroutineDispatcher
14+ import kotlinx.coroutines.CoroutineScope
15+ import kotlinx.coroutines.launch
1816import kotlinx.coroutines.reactor.asCoroutineDispatcher
1917
2018/* *
@@ -64,7 +62,7 @@ class StorageInitializer(
6462 }
6563 if (wasDoInitCalled) {
6664 log.info {
67- " Initialization $storageName is done (reactive part)"
65+ " Initialization of $storageName done (reactive part); started: $isInitStarted ; finished: ${isDone()} ; pending steps: ${pendingStepsCount()} . "
6866 }
6967 }
7068 }
@@ -76,10 +74,13 @@ class StorageInitializer(
7674 require(isInitFinishedCount.decrementAndGet() >= 0 ) {
7775 " Init method cannot be called more than 1 time. Initialization $storageName already finished by another run"
7876 }
79- if (initResult.isNotNull()) {
80- log.info {
81- " Initialization $storageName is done (suspending part)"
77+ log.info {
78+ val status = when {
79+ initResult.isNotNull() -> " done"
80+ else -> " ignored"
8281 }
82+
83+ " Initialization of $storageName $status (suspending part); started: $isInitStarted ; finished: ${isDone()} ; pending steps: ${pendingStepsCount()} ."
8384 }
8485 }
8586 }
@@ -122,6 +123,15 @@ class StorageInitializer(
122123 return action()
123124 }
124125
126+ /* *
127+ * @return the value of [isInitFinishedCount] in a human-readable format.
128+ */
129+ private fun pendingStepsCount (): String =
130+ when (val pendingStepsCount = isInitFinishedCount.get()) {
131+ 0 -> " 0"
132+ else -> " \u2264 $pendingStepsCount "
133+ }
134+
125135 companion object {
126136 private val log: Logger = getLogger<StorageInitializer >()
127137 private val initScheduler: Scheduler = Schedulers .newBoundedElastic(5 , Schedulers .DEFAULT_BOUNDED_ELASTIC_QUEUESIZE , " storage-init-" )
0 commit comments