Skip to content

Commit

Permalink
Fix periodic fetcher #dockerpush #latest
Browse files Browse the repository at this point in the history
  • Loading branch information
smaugfm committed Aug 29, 2023
1 parent aa4c1fe commit 2bd9acb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repositories {
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
implementation("io.github.smaugfm:monobank:0.0.1")
implementation("io.github.smaugfm:monobank:0.0.2")
implementation("io.github.smaugfm:lunchmoney:1.0.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.6.4")
implementation("io.insert-koin:koin-core:$koin")
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version=2.0.0
kotlin.code.style=official
version=1.0.1
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PeriodicFetcherFactory(private val scope: CoroutineScope) {
fetch()
} catch (e: Throwable) {
log.error(e) { "Error fetching $name: " }
delay(interval)
continue
}
if (data === initial) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.serialization.ExperimentalSerializationApi
import mu.KotlinLogging
import org.koin.core.annotation.Single
import reactor.core.publisher.Flux

private val log = KotlinLogging.logger { }

Expand All @@ -20,27 +21,23 @@ class MonoAccountsService(
private val settings: MultipleAccountSettings
) : BankAccountService() {

private val otherAccounts = settings.settings.filterIsInstance<OtherAccountSettings>()
.map { Account(it.accountId, it.alias, it.currency) }
private val monoApis = settings.settings.filterIsInstance<MonoAccountSettings>()
.map { MonoApi(it.token) to it.accountId }

private val fetcher = fetcherFactory.create("Monobank accounts") {
settings.settings.map {
when (it) {
is OtherAccountSettings ->
Account(it.accountId, it.alias, it.currency)

is MonoAccountSettings -> {
val api = MonoApi(it.token)

val accountId = it.accountId
val monoAccount =
api.api.getClientInformation().awaitSingle()
.accounts.firstOrNull { account -> account.id == accountId }!!
Flux.concat(monoApis.map { (api, accountId) ->
api.api.getClientInformation()
.map { info -> info.accounts.first { a -> a.id == accountId } }
.map {
Account(
accountId,
settings.byId[accountId]!!.alias,
monoAccount.currencyCode
it!!.currencyCode
)
}
}
}
}).collectList().awaitSingle() + otherAccounts
}

override suspend fun getAccounts() = fetcher.getData().filter { it.id in settings.accountIds }
Expand Down

0 comments on commit 2bd9acb

Please sign in to comment.