1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-1921 Tech | Integrate Debug Goroutines use case (#522)

This commit is contained in:
Konstantin Ivanov 2023-11-08 16:58:51 +01:00 committed by GitHub
parent d472f3e8d0
commit eda6395124
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 0 deletions

View file

@ -888,4 +888,8 @@ class BlockDataRepository(
override suspend fun createTemplateFromObject(ctx: Id): Id {
return remote.createTemplateFromObject(ctx)
}
override suspend fun debugStackGoroutines(path: String) {
return remote.debugStackGoroutines(path)
}
}

View file

@ -379,4 +379,5 @@ interface BlockRemote {
suspend fun duplicateObjectsList(ids: List<Id>): List<Id>
suspend fun createTemplateFromObject(ctx: Id): Id
suspend fun debugStackGoroutines(path: String)
}

View file

@ -427,4 +427,5 @@ interface BlockRepository {
suspend fun setInternalFlags(command: Command.SetInternalFlags): Payload
suspend fun duplicateObjectsList(ids: List<Id>): List<Id>
suspend fun createTemplateFromObject(ctx: Id): Id
suspend fun debugStackGoroutines(path: String)
}

View file

@ -0,0 +1,18 @@
package com.anytypeio.anytype.domain.debugging
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultInteractor
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import javax.inject.Inject
class DebugGoroutines @Inject constructor(
private val repo: BlockRepository,
dispatchers: AppCoroutineDispatchers
) : ResultInteractor<DebugGoroutines.Params, Unit>(dispatchers.io) {
override suspend fun doWork(params: Params) {
repo.debugStackGoroutines(params.path)
}
data class Params(val path: String)
}

View file

@ -850,4 +850,8 @@ class BlockMiddleware(
override suspend fun createTemplateFromObject(ctx: Id): Id {
return middleware.createTemplateFromObject(ctx)
}
override suspend fun debugStackGoroutines(path: String) {
return middleware.debugStackGoroutines(path)
}
}

View file

@ -2329,6 +2329,16 @@ class Middleware @Inject constructor(
return response.id
}
@Throws(Exception::class)
fun debugStackGoroutines(path: String) {
val request = Rpc.Debug.StackGoroutines.Request(
path = path
)
if (BuildConfig.DEBUG) logRequest(request)
val response = service.debugStackGoroutines(request)
if (BuildConfig.DEBUG) logResponse(response)
}
private fun logRequest(any: Any) {
logger.logRequest(any).also {
if (BuildConfig.DEBUG && threadInfo.isOnMainThread()) {

View file

@ -436,6 +436,9 @@ interface MiddlewareService {
@Throws(Exception::class)
fun debugSubscriptions(request: Rpc.Debug.Subscriptions.Request): Rpc.Debug.Subscriptions.Response
@Throws(Exception::class)
fun debugStackGoroutines(request: Rpc.Debug.StackGoroutines.Request): Rpc.Debug.StackGoroutines.Response
//endregion
//region WIDGETS commands

View file

@ -1719,4 +1719,17 @@ class MiddlewareServiceImplementation @Inject constructor(
return response
}
}
override fun debugStackGoroutines(request: Rpc.Debug.StackGoroutines.Request): Rpc.Debug.StackGoroutines.Response {
val encoded = Service.debugStackGoroutines(
Rpc.Debug.StackGoroutines.Request.ADAPTER.encode(request)
)
val response = Rpc.Debug.StackGoroutines.Response.ADAPTER.decode(encoded)
val error = response.error
if (error != null && error.code != Rpc.Debug.StackGoroutines.Response.Error.Code.NULL) {
throw Exception(error.description)
} else {
return response
}
}
}