Skip to content

Commit

Permalink
Start services according to config
Browse files Browse the repository at this point in the history
  • Loading branch information
tdroxler committed May 2, 2024
1 parent f4d2ec9 commit e9ab6dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,30 @@ explorer {

mempool-sync = {
enable = true,
enable = ${?EXPLORER_MEMPOOL_SYNC_ENABLE}
# Sync interval for MempoolSyncService
sync-period = 5 seconds
sync-period = ${?EXPLORER_SYNC_PERIOD}
}

token-supply = {
enable = true,
enable = ${?EXPLORER_TOKEN_SUPPLY_ENABLE}
# Schedule time for TokenSupplyService
schedule-time = "02:00"
schedule-time = ${?EXPLORER_TOKEN_SUPPLY_SERVICE_SCHEDULE_TIME}
}

hashrate = {
enable = ${?EXPLORER_HASHRATE_ENABLE}
enable = true,
# Sync interval for HashRateService
sync-period = 1 hours
sync-period = ${?EXPLORER_HASH_RATE_SERVICE_SYNC_PERIOD}
}

tx-history = {
enable = ${?EXPLORER_TX_HISTORY_ENABLE}
enable = true,
# Sync interval for TransactionHistoryService
sync-period = 15 minutes
Expand Down
39 changes: 19 additions & 20 deletions app/src/main/scala/org/alephium/explorer/SyncServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

package org.alephium.explorer

import java.time.LocalTime

import scala.collection.immutable.ArraySeq
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._
import scala.util.{Failure, Success, Try}

import com.typesafe.scalalogging.StrictLogging
Expand Down Expand Up @@ -62,11 +59,7 @@ object SyncServices extends StrictLogging {
) flatMap { peers =>
startSyncServices(
peers = peers,
syncPeriod = config.services.blockflowSync.syncPeriod,
tokenSupplyServiceScheduleTime = config.services.tokenSupply.scheduleTime,
hashRateServiceSyncPeriod = config.services.hashrate.syncPeriod,
finalizerServiceSyncPeriod = config.services.finalizer.syncPeriod,
transactionHistoryServiceSyncPeriod = config.services.txHistory.syncPeriod
config = config.services
)
}
}
Expand All @@ -75,11 +68,7 @@ object SyncServices extends StrictLogging {
// scalastyle:off
def startSyncServices(
peers: ArraySeq[Uri],
syncPeriod: FiniteDuration,
tokenSupplyServiceScheduleTime: LocalTime,
hashRateServiceSyncPeriod: FiniteDuration,
finalizerServiceSyncPeriod: FiniteDuration,
transactionHistoryServiceSyncPeriod: FiniteDuration
config: ExplorerConfig.Services
)(implicit
scheduler: Scheduler,
ec: ExecutionContext,
Expand All @@ -93,13 +82,23 @@ object SyncServices extends StrictLogging {
Future
.sequence(
ArraySeq(
BlockFlowSyncService.start(peers, syncPeriod),
MempoolSyncService.start(peers, syncPeriod),
TokenSupplyService.start(tokenSupplyServiceScheduleTime),
HashrateService.start(hashRateServiceSyncPeriod),
FinalizerService.start(finalizerServiceSyncPeriod),
TransactionHistoryService.start(transactionHistoryServiceSyncPeriod)
)
BlockFlowSyncService.start(peers, config.blockflowSync.syncPeriod),
FinalizerService.start(config.finalizer.syncPeriod)
) ++
ArraySeq(
Option.when(config.mempoolSync.enable)(
MempoolSyncService.start(peers, config.mempoolSync.syncPeriod)
),
Option.when(config.tokenSupply.enable)(
TokenSupplyService.start(config.tokenSupply.scheduleTime)
),
Option.when(config.hashrate.enable)(
HashrateService.start(config.hashrate.syncPeriod)
),
Option.when(config.txHistory.enable)(
TransactionHistoryService.start(config.txHistory.syncPeriod)
)
).flatten
)
.onComplete {
case Failure(error) =>
Expand Down

0 comments on commit e9ab6dc

Please sign in to comment.