Skip to content

Commit

Permalink
add delayed init start for dlob historical cron job, various other re…
Browse files Browse the repository at this point in the history
…factors
  • Loading branch information
nullpointer0x00 committed Oct 25, 2023
1 parent 497002d commit 042c54f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,13 @@ class TokenService(private val accountClient: AccountGrpcClient) {
}
}

fun getHistoricalFromDlob(startTime: DateTime): DlobHistBase {
fun getHistoricalFromDlob(startTime: DateTime): DlobHistBase? {
val tickerIds = listOf("HASH_USD", "HASH_USDOMNI")

val dlobHistorical = tickerIds
.mapNotNull { getHistoricalFromDlob(startTime, it)?.buy }
.flatten()
.flatMap { getHistoricalFromDlob(startTime, it)?.buy.orEmpty() }

return DlobHistBase(dlobHistorical)
return if (dlobHistorical.isNotEmpty()) DlobHistBase(dlobHistorical) else null
}

fun getTokenHistorical(fromDate: DateTime?, toDate: DateTime?) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ import tendermint.types.BlockOuterClass
import java.math.BigDecimal
import java.time.OffsetDateTime
import java.time.ZoneOffset
import javax.annotation.PostConstruct


@Service
class AsyncService(
Expand All @@ -104,7 +106,19 @@ class AsyncService(
protected val logger = logger(AsyncService::class)
protected var collectHistorical = true

@Scheduled(initialDelay = 0L, fixedDelay = 5000L)
@PostConstruct
fun asyncServiceOnStartInit() {
Thread {
try {
Thread.sleep(5000)
updateTokenHistorical()
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}
}.start()
}

@Scheduled(initialDelay = 0L, fixedDelay = 5000L)
fun updateLatestBlockHeightJob() {
val index = getBlockIndex()
val startHeight = blockService.getLatestBlockHeight()
Expand Down Expand Up @@ -145,7 +159,7 @@ class AsyncService(
}

fun getBlockIndex() = blockService.getBlockIndexFromCache()?.let {
Pair<Int?, Int?>(it.maxHeightRead, it.minHeightRead)
Pair(it.maxHeightRead, it.minHeightRead)
}

fun startCollectingHistoricalBlocks(blockIndex: Pair<Int?, Int?>?) =
Expand Down Expand Up @@ -248,11 +262,11 @@ class AsyncService(
val now = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC).toString()
cacheService.getCacheValue(key)!!.let { cache ->
pricingService.getPricingAsync(cache.cacheValue!!, "async pricing update").forEach { price ->
// dont set price from PE
// don't set price from PE
if (price.markerDenom != UTILITY_TOKEN) {
assetService.getAssetRaw(price.markerDenom).let { pricingService.insertAssetPricing(it, price) }
} else {
// Pull price from CMC, calced to the true base denom price
// Pull price from CMC, calculate to the true base denom price
val cmcPrice =
tokenService.getTokenLatest()?.quote?.get(USD_UPPER)?.price
?.let {
Expand Down Expand Up @@ -281,7 +295,7 @@ class AsyncService(
fun updateTokenHistorical() {
val today = DateTime.now().startOfDay()
var startDate = today.minusMonths(1)
var latest = TokenHistoricalDailyRecord.getLatestDateEntry()
val latest = TokenHistoricalDailyRecord.getLatestDateEntry()
if (latest != null) {
startDate = latest.timestamp.minusDays(1)
}
Expand Down

0 comments on commit 042c54f

Please sign in to comment.