Skip to content

Commit 723b59a

Browse files
committed
refactor: orchestraing, rollback 과정중 실패하면 로깅을 남긴다
1 parent 49f87b7 commit 723b59a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/main/kotlin/org/gitanimals/core/OrchestratorExtension.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
44
import org.rooftop.netx.api.Context
55
import org.rooftop.netx.api.ContextOrchestrate
66
import org.rooftop.netx.api.ContextRollback
7+
import org.slf4j.LoggerFactory
78
import org.slf4j.MDC
89

910
open class TraceIdContextOrchestrator<T : Any, V : Any>(
@@ -12,10 +13,19 @@ open class TraceIdContextOrchestrator<T : Any, V : Any>(
1213

1314
override fun orchestrate(context: Context, request: T): V {
1415
MDC.put(TRACE_ID, context.decodeContext(TRACE_ID, String::class))
15-
return orchestrate.orchestrate(context, request).also {
16+
return runCatching {
17+
orchestrate.orchestrate(context, request)
18+
}.getOrElse {
19+
logger.warn("Orchestrating fail, rollback start. request: \"$request\"", it)
20+
throw it
21+
}.also {
1622
MDC.remove(TRACE_ID)
1723
}
1824
}
25+
26+
private companion object {
27+
private val logger = LoggerFactory.getLogger(this::class.simpleName)
28+
}
1929
}
2030

2131
open class TraceIdContextRollback<T : Any, V : Any?>(
@@ -24,8 +34,17 @@ open class TraceIdContextRollback<T : Any, V : Any?>(
2434

2535
override fun rollback(context: Context, request: T): V {
2636
MDC.put(TRACE_ID, context.decodeContext(TRACE_ID, String::class))
27-
return rollback.rollback(context, request).also {
37+
return runCatching {
38+
rollback.rollback(context, request)
39+
}.getOrElse {
40+
logger.error("Rollback fail need to fix. request: \"$request\"", it)
41+
throw it
42+
}.also {
2843
MDC.remove(TRACE_ID)
2944
}
3045
}
46+
47+
private companion object {
48+
private val logger = LoggerFactory.getLogger(this::class.simpleName)
49+
}
3150
}

0 commit comments

Comments
 (0)