-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hyperschwartz/jschwartz/async-processing-f…
…or-invoices-and-better-oracle-approval Add coroutine launches for event processing and failure retries
- Loading branch information
Showing
11 changed files
with
126 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
server/src/main/kotlin/io/provenance/invoice/config/app/CoroutineScopeNames.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.provenance.invoice.config.app | ||
|
||
object CoroutineScopeNames { | ||
const val EVENT_STREAM_SCOPE = "event-stream-scope" | ||
const val FAILURE_RETRY_SCOPE = "failure-retry-scope" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
server/src/main/kotlin/io/provenance/invoice/util/coroutine/CoroutineExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.provenance.invoice.util.coroutine | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.CoroutineStart | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.slf4j.MDCContext | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
fun CoroutineScope.launchI( | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
start: CoroutineStart = CoroutineStart.DEFAULT, | ||
block: suspend CoroutineScope.() -> Unit, | ||
): Job = launch(context + MDCContext(), start, block) |
22 changes: 22 additions & 0 deletions
22
server/src/main/kotlin/io/provenance/invoice/util/coroutine/CoroutineUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.provenance.invoice.util.coroutine | ||
|
||
import io.micrometer.core.instrument.util.NamedThreadFactory | ||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.asCoroutineDispatcher | ||
import mu.KotlinLogging | ||
import java.util.concurrent.Executors | ||
|
||
object CoroutineUtil { | ||
private val logger = KotlinLogging.logger {} | ||
|
||
fun newSingletonScope( | ||
scopeName: String, | ||
threadCount: Int, | ||
) : CoroutineScope = Executors.newFixedThreadPool(threadCount, NamedThreadFactory(scopeName)) | ||
.asCoroutineDispatcher() | ||
.plus(CoroutineExceptionHandler { _, throwable -> logger.error("Coroutine execution failed", throwable) }) | ||
.plus(SupervisorJob()) | ||
.let(::CoroutineScope) | ||
} |