-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance missing uploads monitoring on Sentry
- Loading branch information
Showing
5 changed files
with
30 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 22 additions & 10 deletions
32
composeApp/src/commonMain/kotlin/org/ooni/probe/domain/CheckSkipAutoRunNotUploadedLimit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
package org.ooni.probe.domain | ||
|
||
import co.touchlab.kermit.Logger | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.first | ||
import org.ooni.probe.data.models.SettingsKey | ||
|
||
class CheckSkipAutoRunNotUploadedLimit( | ||
private val countResultsMissingUpload: () -> Flow<Long>, | ||
private val getPreferenceValueByKey: (SettingsKey) -> Flow<Any?>, | ||
) { | ||
operator fun invoke(): Flow<Boolean> = | ||
combine( | ||
getPreferenceValueByKey(SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT), | ||
countResultsMissingUpload(), | ||
) { limit, count -> | ||
val notUploadedLimit = (limit as? Int) | ||
?.coerceAtLeast(1) | ||
?: BootstrapPreferences.NOT_UPLOADED_LIMIT_DEFAULT | ||
count >= notUploadedLimit | ||
suspend operator fun invoke(): Boolean { | ||
val limitPreference = | ||
getPreferenceValueByKey(SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT).first() | ||
val count = countResultsMissingUpload().first() | ||
|
||
val notUploadedLimit = (limitPreference as? Int) | ||
?.coerceAtLeast(1) | ||
?: BootstrapPreferences.NOT_UPLOADED_LIMIT_DEFAULT | ||
val shouldSkip = count >= notUploadedLimit | ||
|
||
if (shouldSkip) { | ||
Logger.w( | ||
"Skipping auto-run due to not uploaded limit", | ||
SkipAutoRunException("Results missing upload: $count (limit=$notUploadedLimit)"), | ||
) | ||
} | ||
|
||
return shouldSkip | ||
} | ||
} | ||
|
||
class SkipAutoRunException(message: String) : Exception(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters