Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5] Pause operation repo and retry failed user create #1900

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ enum class ExecutionResult {
* The operation failed due to a conflict and can be handled.
*/
FAIL_CONFLICT,

/**
* Used in special create user case.
* The operation failed due to a non-retryable error. Pause the operation repo
* and retry on a new session, giving the SDK a chance to recover from the failed user create.
*/
FAIL_PAUSE_OPREPO,
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class OperationRepo(
private val executorsMap: Map<String, IOperationExecutor>
private val queue = mutableListOf<OperationQueueItem>()
private val waiter = WaiterWithValue<Boolean>()
private var paused = false

init {
val executorsMap: MutableMap<String, IOperationExecutor> = mutableMapOf()
Expand All @@ -47,6 +48,7 @@ internal class OperationRepo(
}

override fun start() {
paused = false
suspendifyOnThread(name = "OpRepo") {
processQueueForever()
}
Expand Down Expand Up @@ -99,6 +101,10 @@ internal class OperationRepo(

// This runs forever, until the application is destroyed.
while (true) {
if (paused) {
Logging.debug("OperationRepo is paused")
return
}
try {
var ops: List<OperationQueueItem>? = null

Expand Down Expand Up @@ -199,6 +205,15 @@ internal class OperationRepo(
ops.reversed().forEach { queue.add(0, it) }
}
}
ExecutionResult.FAIL_PAUSE_OPREPO -> {
Logging.error("Operation execution failed with eventual retry, pausing the operation repo: $operations")
// keep the failed operation and pause the operation repo from executing
paused = true
// add back all operations to the front of the queue to be re-executed.
synchronized(queue) {
ops.reversed().forEach { queue.add(0, it) }
}
}
}

// if there are operations provided on the result, we need to enqueue them at the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ internal class LoginUserOperationExecutor(
NetworkUtils.ResponseStatusType.UNAUTHORIZED ->
ExecutionResponse(ExecutionResult.FAIL_UNAUTHORIZED)
else ->
ExecutionResponse(ExecutionResult.FAIL_NORETRY)
ExecutionResponse(ExecutionResult.FAIL_PAUSE_OPREPO)
}
}
}
Expand Down
Loading