fix(#516): don't retry a run only blocked series failed, back up on any interval switch
This commit is contained in:
1 parent
4d342c98ad
commit
242ccd3b70
5 files changed
+54
-19
No files matched your search
@@ -78,8 +78,8 @@ object BackupScheduler {
|
||||
|
||||
/**
|
||||
* Reconcile the scheduled work with the saved settings: enqueue a unique
|
||||
* periodic request when backup is on and a folder is set, otherwise cancel
|
||||
* it. WorkManager persists the request across reboots on its own.
|
||||
* periodic request when backup is on, a folder is set and the interval
|
||||
* isn't switched off (#516), otherwise cancel it. WorkManager persists the request across reboots on its own.
|
||||
*
|
||||
* The first run is delayed by one interval so it doesn't follow an immediate
|
||||
* [runNow] with a near-identical copy. With backing up after changes on
|
||||
@@ -267,7 +267,8 @@ class BackupWorker(
|
||||
return if (outcome == RunOutcome.Failed && !changeRun) Result.retry() else Result.success()
|
||||
}
|
||||
|
||||
private enum class RunOutcome { Written, PartlyFailed, Failed, NothingToDo }
|
||||
/** [Blocked]: failed only on series no retry can back up, so it isn't retried. */
|
||||
private enum class RunOutcome { Written, PartlyFailed, Failed, Blocked, NothingToDo }
|
||||
|
||||
/** How a stable copy's write went: under its own name, under one the provider picked, or not at all. */
|
||||
private enum class LatestWrite { Landed, Renamed, Failed }
|
||||
@@ -397,11 +398,13 @@ class BackupWorker(
|
||||
|
||||
var written = 0
|
||||
var failed = 0
|
||||
var blocked = 0
|
||||
val landedLatest = mutableSetOf<String>()
|
||||
for (plan in plans) {
|
||||
val target = plan.target
|
||||
if (!plan.backedUp(intervalOn)) {
|
||||
failed++
|
||||
blocked++
|
||||
continue
|
||||
}
|
||||
if (changeRun) {
|
||||
@@ -447,6 +450,7 @@ class BackupWorker(
|
||||
return when {
|
||||
failed == 0 && written == 0 -> RunOutcome.NothingToDo
|
||||
failed == 0 -> RunOutcome.Written
|
||||
written == 0 && failed == blocked -> RunOutcome.Blocked
|
||||
written == 0 -> RunOutcome.Failed
|
||||
else -> RunOutcome.PartlyFailed
|
||||
}
|
||||
|
||||
@@ -231,6 +231,10 @@ class SettingsPrefs @Inject constructor(
|
||||
val autoBackupLedger: Flow<BackupLedger> = prefs.flow(SettingsKeys.autoBackupLedger)
|
||||
val autoBackupOnChange: Flow<Boolean> = prefs.flow(SettingsKeys.autoBackupOnChange)
|
||||
val autoBackupScheduled: Flow<Boolean> = prefs.snapshot { it.autoBackupScheduled }
|
||||
|
||||
/** Read together, so the screen never shows one updated without the other. */
|
||||
val autoBackupOnChangeAndScheduled: Flow<Pair<Boolean, Boolean>> =
|
||||
prefs.snapshot { it[SettingsKeys.autoBackupOnChange] to it.autoBackupScheduled }
|
||||
val autoBackupFingerprints: Flow<BackupFingerprints> = prefs.flow(SettingsKeys.autoBackupFingerprints)
|
||||
val specialDatesEnabled: Flow<Boolean> = prefs.flow(SettingsKeys.specialDatesEnabled)
|
||||
val specialDatesTypes: Flow<Set<SpecialDateType>> = prefs.snapshot { it.specialDatesTypes }
|
||||
@@ -525,13 +529,27 @@ class SettingsPrefs @Inject constructor(
|
||||
|
||||
suspend fun setAutoBackupKeep(keep: Int) = prefs.set(SettingsKeys.autoBackupKeep, keep)
|
||||
|
||||
suspend fun setAutoBackupOnChange(enabled: Boolean) {
|
||||
prefs.edit { applyAutoBackupOnChange(it, enabled) }
|
||||
/** Returns whether this switched the interval on or off. */
|
||||
suspend fun setAutoBackupOnChange(enabled: Boolean): Boolean = editAutoBackupScheduled {
|
||||
applyAutoBackupOnChange(it, enabled)
|
||||
}
|
||||
|
||||
/** Off only sticks while backing up after changes is on; see [applyAutoBackupOnChange]. */
|
||||
suspend fun setAutoBackupScheduled(enabled: Boolean) {
|
||||
prefs.edit { if (enabled || it[SettingsKeys.autoBackupOnChange]) it[SettingsKeys.autoBackupScheduledStored] = enabled }
|
||||
/**
|
||||
* Off only sticks while backing up after changes is on; see
|
||||
* [applyAutoBackupOnChange]. Returns whether this switched the interval.
|
||||
*/
|
||||
suspend fun setAutoBackupScheduled(enabled: Boolean): Boolean = editAutoBackupScheduled {
|
||||
if (enabled || it[SettingsKeys.autoBackupOnChange]) it[SettingsKeys.autoBackupScheduledStored] = enabled
|
||||
}
|
||||
|
||||
private suspend fun editAutoBackupScheduled(transform: (MutablePreferences) -> Unit): Boolean {
|
||||
var switched = false
|
||||
prefs.edit {
|
||||
val before = it.autoBackupScheduled
|
||||
transform(it)
|
||||
switched = it.autoBackupScheduled != before
|
||||
}
|
||||
return switched
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -109,7 +109,7 @@ class CalendarsViewModel @Inject constructor(
|
||||
settingsPrefs.autoBackupSelection,
|
||||
settingsPrefs.autoBackupCombined,
|
||||
settingsPrefs.autoBackupKeep,
|
||||
combine(settingsPrefs.autoBackupOnChange, settingsPrefs.autoBackupScheduled, ::Pair),
|
||||
settingsPrefs.autoBackupOnChangeAndScheduled,
|
||||
) { base, selection, combined, keep, (onChange, scheduled) ->
|
||||
base.copy(selection = selection, combined = combined, keep = keep, onChange = onChange, scheduled = scheduled)
|
||||
}
|
||||
@@ -296,20 +296,21 @@ class CalendarsViewModel @Inject constructor(
|
||||
|
||||
fun setAutoBackupOnChange(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
val wasScheduled = settingsPrefs.autoBackupScheduled.first()
|
||||
settingsPrefs.setAutoBackupOnChange(enabled)
|
||||
val switched = settingsPrefs.setAutoBackupOnChange(enabled)
|
||||
reschedule()
|
||||
if (!wasScheduled && settingsPrefs.autoBackupScheduled.first()) runBackupIfActive()
|
||||
if (switched) runBackupIfActive()
|
||||
}
|
||||
}
|
||||
|
||||
/** Back on, it backs up right away rather than an interval later. */
|
||||
/**
|
||||
* Switching the interval backs up right away: back on, rather than an
|
||||
* interval later; off, so a series only its dated files covered shows up.
|
||||
*/
|
||||
fun setAutoBackupScheduled(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
val wasScheduled = settingsPrefs.autoBackupScheduled.first()
|
||||
settingsPrefs.setAutoBackupScheduled(enabled)
|
||||
val switched = settingsPrefs.setAutoBackupScheduled(enabled)
|
||||
reschedule()
|
||||
if (!wasScheduled && settingsPrefs.autoBackupScheduled.first()) runBackupIfActive()
|
||||
if (switched) runBackupIfActive()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -962,6 +962,17 @@ class SettingsPrefsTest {
|
||||
assertThat(prefs.autoBackupScheduled.first()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the interval setters report whether they switched it`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
assertThat(prefs.setAutoBackupScheduled(false)).isFalse()
|
||||
assertThat(prefs.setAutoBackupOnChange(true)).isFalse()
|
||||
assertThat(prefs.setAutoBackupScheduled(false)).isTrue()
|
||||
assertThat(prefs.setAutoBackupScheduled(false)).isFalse()
|
||||
assertThat(prefs.setAutoBackupOnChange(false)).isTrue()
|
||||
assertThat(prefs.autoBackupOnChangeAndScheduled.first()).isEqualTo(false to true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `switching the interval off without after-change backups leaves nothing behind`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
|
||||
@@ -647,9 +647,10 @@ While the option is on, the interval itself can be switched off
|
||||
off without the option): the periodic work is cancelled and no run writes or
|
||||
prunes dated files. Run-now then rewrites every stable copy, change runs only
|
||||
the changed ones, and a series whose stable name a file of the user's holds
|
||||
counts as failed, since nothing else backs it up. Turning the option off sets
|
||||
the interval back on, at the interval it had, and turning the interval back on
|
||||
either way backs up right away.
|
||||
counts as failed (not retried), since nothing else backs it up. Turning the
|
||||
option off sets the interval back on, at the interval it had; any switch of the
|
||||
interval backs up right away. What the text above leaves to the next scheduled
|
||||
run then waits for the next run-now.
|
||||
|
||||
**A backup carries the series' deleted and moved occurrences.** `EXDATE` lives on
|
||||
the master row and is part of `EventExportProjection`; `IcsWriter` marks an
|
||||
|
||||
Reference in new issue
Block a user