-
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.
Merge pull request #85 from CrisisCleanup/production-switchover
Production switchover
- Loading branch information
Showing
41 changed files
with
687 additions
and
169 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
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/crisiscleanup/ExternalIntentProcessor.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.crisiscleanup | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import com.crisiscleanup.core.common.event.AuthEventBus | ||
import com.crisiscleanup.core.common.log.AppLogger | ||
import com.crisiscleanup.core.common.log.CrisisCleanupLoggers | ||
import com.crisiscleanup.core.common.log.Logger | ||
import javax.inject.Inject | ||
|
||
class ExternalIntentProcessor @Inject constructor( | ||
private val authEventBus: AuthEventBus, | ||
@Logger(CrisisCleanupLoggers.App) private val logger: AppLogger, | ||
) { | ||
fun processMainIntent(intent: Intent) { | ||
when (val action = intent.action) { | ||
Intent.ACTION_VIEW -> { | ||
intent.data?.let { intentUri -> | ||
intentUri.path?.let { urlPath -> | ||
processMainIntent(intentUri, urlPath) | ||
} | ||
} | ||
} | ||
|
||
else -> { | ||
logger.logDebug("Main intent action not handled $action") | ||
} | ||
} | ||
} | ||
|
||
private fun processMainIntent(url: Uri, urlPath: String) { | ||
if (urlPath.startsWith("/o/callback")) { | ||
url.getQueryParameter("code")?.let { code -> | ||
authEventBus.onEmailLoginLink(code) | ||
} | ||
} else if (urlPath.startsWith("/password/reset/")) { | ||
val code = urlPath.replace("/password/reset/", "") | ||
if (code.isNotBlank()) { | ||
authEventBus.onResetPassword(code) | ||
} | ||
} | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/crisiscleanup/SwitchProductionApiManager.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.crisiscleanup | ||
|
||
import com.crisiscleanup.core.common.log.AppLogger | ||
import com.crisiscleanup.core.data.repository.AppDataManagementRepository | ||
import com.crisiscleanup.core.data.repository.ClearAppDataStep | ||
import com.crisiscleanup.core.data.repository.LocalAppMetricsRepository | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.stateIn | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
class SwitchProductionApiManager( | ||
private val appMetricsRepository: LocalAppMetricsRepository, | ||
private val appDataRepository: AppDataManagementRepository, | ||
private val logger: AppLogger, | ||
coroutineScope: CoroutineScope, | ||
) { | ||
private val hasRunSwitchover = AtomicBoolean() | ||
private val productionSwitchStep = appDataRepository.clearingAppDataStep | ||
.map { | ||
if (appDataRepository.clearAppDataError != ClearAppDataStep.None) { | ||
logger.logException(Exception("Switchover failed $it")) | ||
} else { | ||
logger.logCapture("Switchover on $it") | ||
} | ||
it | ||
} | ||
val isSwitchingToProduction = productionSwitchStep | ||
.map { it != ClearAppDataStep.None } | ||
.stateIn( | ||
scope = coroutineScope, | ||
initialValue = false, | ||
started = SharingStarted.WhileSubscribed(), | ||
) | ||
|
||
private val productionSwitchMessageLookup = mapOf( | ||
ClearAppDataStep.None to "Getting ready...", | ||
ClearAppDataStep.StopSyncPull to "Stopping background data sync...", | ||
ClearAppDataStep.SyncPush to "Saving changes to cloud...", | ||
ClearAppDataStep.ClearData to "Clearing existing data...", | ||
ClearAppDataStep.DatabaseNotCleared to "Unable to clear data", | ||
ClearAppDataStep.FinalClear to "Finalizing", | ||
ClearAppDataStep.Cleared to "App is ready!", | ||
) | ||
val productionSwitchMessage = productionSwitchStep | ||
.map { | ||
productionSwitchMessageLookup[it] ?: "Something is happening..." | ||
} | ||
.stateIn( | ||
scope = coroutineScope, | ||
initialValue = "", | ||
started = SharingStarted.WhileSubscribed(), | ||
) | ||
|
||
suspend fun switchToProduction() { | ||
if (!hasRunSwitchover.getAndSet(true) && | ||
appMetricsRepository.metrics.first().switchToProductionApiVersion < 143 | ||
) { | ||
appDataRepository.clearAppData() | ||
} | ||
} | ||
} |
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
Oops, something went wrong.