mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-22 20:46:18 -06:00
Add skipping migration when previous attempt failed (#2508)
This commit is contained in:
parent
254719f22f
commit
d799ec7ac9
@ -23,6 +23,7 @@ class WulkanowySdkFactory @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
private val eduOneMutex = Mutex()
|
private val eduOneMutex = Mutex()
|
||||||
|
private val migrationFailedStudentIds = mutableSetOf<Long>()
|
||||||
|
|
||||||
private val sdk = Sdk().apply {
|
private val sdk = Sdk().apply {
|
||||||
androidVersion = android.os.Build.VERSION.RELEASE
|
androidVersion = android.os.Build.VERSION.RELEASE
|
||||||
@ -78,14 +79,24 @@ class WulkanowySdkFactory @Inject constructor(
|
|||||||
private suspend fun checkEduOneAndMigrateIfNecessary(student: Student): Boolean {
|
private suspend fun checkEduOneAndMigrateIfNecessary(student: Student): Boolean {
|
||||||
if (student.isEduOne != null) return student.isEduOne
|
if (student.isEduOne != null) return student.isEduOne
|
||||||
|
|
||||||
|
if (student.id in migrationFailedStudentIds) {
|
||||||
|
Timber.i("Migration eduOne: skipping because of previous failure")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
eduOneMutex.withLock {
|
eduOneMutex.withLock {
|
||||||
|
if (student.id in migrationFailedStudentIds) {
|
||||||
|
Timber.i("Migration eduOne: skipping because of previous failure")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
val studentFromDatabase = studentDb.loadById(student.id)
|
val studentFromDatabase = studentDb.loadById(student.id)
|
||||||
if (studentFromDatabase?.isEduOne != null) {
|
if (studentFromDatabase?.isEduOne != null) {
|
||||||
Timber.d("Migration eduOne: already done")
|
Timber.i("Migration eduOne: already done")
|
||||||
return studentFromDatabase.isEduOne
|
return studentFromDatabase.isEduOne
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.d("Migration eduOne: flag missing. Running migration...")
|
Timber.i("Migration eduOne: flag missing. Running migration...")
|
||||||
val initializedSdk = buildSdk(
|
val initializedSdk = buildSdk(
|
||||||
student = student,
|
student = student,
|
||||||
semester = null,
|
semester = null,
|
||||||
@ -96,7 +107,8 @@ class WulkanowySdkFactory @Inject constructor(
|
|||||||
.getOrNull()
|
.getOrNull()
|
||||||
|
|
||||||
if (newCurrentStudent == null) {
|
if (newCurrentStudent == null) {
|
||||||
Timber.d("Migration eduOne: failed, so skipping")
|
Timber.i("Migration eduOne: failed, so skipping")
|
||||||
|
migrationFailedStudentIds.add(student.id)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,10 @@ class SemesterRepository @Inject constructor(
|
|||||||
.getSemesters()
|
.getSemesters()
|
||||||
.mapToEntities(student.studentId)
|
.mapToEntities(student.studentId)
|
||||||
|
|
||||||
if (new.isEmpty()) return Timber.i("Empty semester list!")
|
if (new.isEmpty()) {
|
||||||
|
Timber.i("Empty semester list from SDK!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val old = semesterDb.loadAll(student)
|
val old = semesterDb.loadAll(student)
|
||||||
semesterDb.removeOldAndSaveNew(
|
semesterDb.removeOldAndSaveNew(
|
||||||
|
Loading…
Reference in New Issue
Block a user