Skip to content

Commit 3ad85b2

Browse files
committed
fix: login operation not removed from queue within postCreateDelay
1 parent 9cf7cd0 commit 3ad85b2

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,6 @@ internal class OperationRepo(
241241
queue.forEach { it.operation.translateIds(response.idTranslations) }
242242
}
243243
response.idTranslations.values.forEach { _newRecordState.add(it) }
244-
// Stall processing the queue so the backend's DB has to time
245-
// reflect the change before we do any other operations to it.
246-
// NOTE: Future: We could run this logic in a
247-
// coroutineScope.launch() block so other operations not
248-
// effecting this these id's can still be done in parallel,
249-
// however other parts of the system don't currently account
250-
// for this so this is not safe to do.
251-
val waitTime = _configModelStore.model.opRepoPostCreateDelay
252-
delay(waitTime)
253-
synchronized(queue) {
254-
if (queue.isNotEmpty()) waiter.wake(LoopWaiterMessage(false, waitTime))
255-
}
256244
}
257245

258246
var highestRetries = 0
@@ -316,7 +304,11 @@ internal class OperationRepo(
316304
}
317305
}
318306

307+
// wait for retry and post create waiters to start next operation
319308
delayBeforeNextExecution(highestRetries, response.retryAfterSeconds)
309+
if (response.idTranslations != null) {
310+
delayForPostCreate(_configModelStore.model.opRepoPostCreateDelay)
311+
}
320312
} catch (e: Throwable) {
321313
Logging.log(LogLevel.ERROR, "Error attempting to execute operation: $ops", e)
322314

@@ -345,6 +337,22 @@ internal class OperationRepo(
345337
}
346338
}
347339

340+
/**
341+
* Stall processing the queue so the backend's DB has to time
342+
* reflect the change before we do any other operations to it.
343+
* NOTE: Future: We could run this logic in a
344+
* coroutineScope.launch() block so other operations not
345+
* effecting this these id's can still be done in parallel,
346+
* however other parts of the system don't currently account
347+
* for this so this is not safe to do.
348+
*/
349+
suspend fun delayForPostCreate(postCreateDelay: Long) {
350+
delay(postCreateDelay)
351+
synchronized(queue) {
352+
if (queue.isNotEmpty()) waiter.wake(LoopWaiterMessage(false, postCreateDelay))
353+
}
354+
}
355+
348356
internal fun getNextOps(bucketFilter: Int): List<OperationQueueItem>? {
349357
return synchronized(queue) {
350358
val startingOp =

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/core/internal/operations/OperationRepoTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class OperationRepoTests : FunSpec({
215215
// Given
216216
val mocks = Mocks()
217217
val opRepo = mocks.operationRepo
218-
coEvery { opRepo.delayBeforeNextExecution(any(), any()) } just runs
218+
coEvery { opRepo.delayBeforeNextExecution(any(), any(), any()) } just runs
219219
coEvery {
220220
mocks.executor.execute(any())
221221
} returns ExecutionResponse(ExecutionResult.FAIL_RETRY) andThen ExecutionResponse(ExecutionResult.SUCCESS)
@@ -239,7 +239,7 @@ class OperationRepoTests : FunSpec({
239239
it[0] shouldBe operation
240240
},
241241
)
242-
opRepo.delayBeforeNextExecution(1, null)
242+
opRepo.delayBeforeNextExecution(1, null, 0)
243243
mocks.executor.execute(
244244
withArg {
245245
it.count() shouldBe 1

0 commit comments

Comments
 (0)