MigrationProgress
Represents the progress state of a migration operation.
MigrationProgress is a sealed class hierarchy that tracks the various states of a migration process. It's emitted as a Flow from the Migration.migrate() method, allowing consumers to monitor migration progress, handle errors, and provide user feedback.
Progress Flow Sequence:
A typical migration follows this progress sequence:
Started - Migration begins
InProgress - For each step being executed
StepCompleted - After each step completes successfully
Success - When all steps complete, OR
Error - If any step fails with an exception
Usage Example:
migration.migrate(context).collect { progress ->
when (progress) {
is MigrationProgress.Started -> {
showProgressDialog()
updateStatus("Migration starting...")
}
is MigrationProgress.InProgress -> {
updateProgressBar(progress.currentStep, progress.totalSteps)
updateStatus("Step ${progress.currentStep}/${progress.totalSteps}: ${progress.message}")
}
is MigrationProgress.StepCompleted -> {
logStepCompletion(progress.step.description)
}
is MigrationProgress.Success -> {
hideProgressDialog()
showSuccessMessage(progress.message ?: "Migration completed")
}
is MigrationProgress.Error -> {
hideProgressDialog()
showErrorDialog("Migration failed at step: ${progress.step.description}", progress.error)
}
}
}Error Handling:
When a migration step throws an exception, the migration process stops and emits an Error progress state. The error contains both the exception and the step where the failure occurred:
is MigrationProgress.Error -> {
logger.e("Migration failed at step: ${progress.step.description}", progress.error)
// Handle specific error types
when (progress.error) {
is NetworkException -> retryMigration()
is DataCorruptionException -> resetAndRestart()
else -> showGenericError()
}
}See also
Inheritors
Types
Migration failed with an error.
Migration is in progress with current step information.
Migration has started.
A migration step has completed successfully.
Migration completed successfully.