MigrationProgress

sealed class 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:

  1. Started - Migration begins

  2. InProgress - For each step being executed

  3. StepCompleted - After each step completes successfully

  4. Success - When all steps complete, OR

  5. 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

Constructors

Link copied to clipboard
protected constructor()

Types

Link copied to clipboard
data class Error(val error: Throwable, val step: MigrationStep) : MigrationProgress

Migration failed with an error.

Link copied to clipboard
data class InProgress(val currentStep: Int, val step: MigrationStep, val totalSteps: Int, val message: String? = null) : MigrationProgress

Migration is in progress with current step information.

Link copied to clipboard

Migration has started.

Link copied to clipboard

A migration step has completed successfully.

Link copied to clipboard
data class Success(val message: String? = null) : MigrationProgress

Migration completed successfully.