|
2 | 2 | {-# LANGUAGE DataKinds #-}
|
3 | 3 | {-# LANGUAGE DeriveGeneric #-}
|
4 | 4 | {-# LANGUAGE DuplicateRecordFields #-}
|
| 5 | +{-# LANGUAGE FlexibleContexts #-} |
5 | 6 | {-# LANGUAGE FlexibleInstances #-}
|
6 | 7 | {-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
7 | 8 | {-# LANGUAGE MultiParamTypeClasses #-}
|
@@ -202,10 +203,32 @@ readWalletBalance
|
202 | 203 | -> PaymentSource
|
203 | 204 | -> ExceptT InitFaucetError m Int64
|
204 | 205 | readWalletBalance client (psWalletId -> wId) = do
|
205 |
| - lift $ logInfo "Reading initial wallet balance" |
| 206 | + -- lift $ logInfo "Reading initial wallet balance" |
206 | 207 | (fromIntegral . getCoin . unV1 . walBalance)
|
207 | 208 | <$> runClient CouldntReadBalance (getWallet client wId)
|
208 | 209 |
|
| 210 | +-------------------------------------------------------------------------------- |
| 211 | +-- | Monitor a wallet's balance |
| 212 | +-- |
| 213 | +-- Sets the wallet's balance in the 'Gauge.Gauge' every 5 seconds |
| 214 | +monitorWalletBalance |
| 215 | + :: (HasLoggerName m, CanLog m, MonadIO m) |
| 216 | + => FaucetEnv -> m () |
| 217 | +monitorWalletBalance fEnv = do |
| 218 | + let wc = fEnv ^. feWalletClient . to liftClient |
| 219 | + paymentSource = fEnv ^. (feSourceWallet . to cfgToPaymentSource) |
| 220 | + balGauge = fEnv ^. feWalletBalance |
| 221 | + forever $ do |
| 222 | + liftIO $ threadDelay 5000000 |
| 223 | + eBal <- runExceptT $ readWalletBalance wc paymentSource |
| 224 | + case eBal of |
| 225 | + Left err -> do |
| 226 | + logError ("Error reading balance: " <> (Text.pack $ show err)) |
| 227 | + Right bal -> do |
| 228 | + logInfo ("Read wallet balance: " <> (Text.pack $ show bal)) |
| 229 | + liftIO $ Gauge.set balGauge bal |
| 230 | + |
| 231 | +-------------------------------------------------------------------------------- |
209 | 232 | -- | Gets an address out of an existing wallet
|
210 | 233 | --
|
211 | 234 | -- Fails with 'BadAddress'
|
@@ -311,8 +334,14 @@ initEnv fc store = do
|
311 | 334 | withSublogger "initEnv" $ logInfo "Initializing environment"
|
312 | 335 | env <- createEnv
|
313 | 336 | withSublogger "initEnv" $ logInfo "Created environment"
|
314 |
| - tID <- liftLogIO forkIO $ processWithdrawls env |
315 |
| - withSublogger "initEnv" $ logInfo ("Forked thread for processing withdrawls:" <> show tID ^. packed) |
| 337 | + wdTId <- liftLogIO forkIO $ processWithdrawls env |
| 338 | + withSublogger "initEnv" |
| 339 | + $ logInfo ( "Forked thread for processing withdrawls:" |
| 340 | + <> show wdTId ^. packed) |
| 341 | + monTId <- liftLogIO forkIO $ monitorWalletBalance env |
| 342 | + withSublogger "initEnv" |
| 343 | + $ logInfo ( "Forked thread for monitoring the wallet balance:" |
| 344 | + <> show monTId ^. packed) |
316 | 345 | return env
|
317 | 346 | where
|
318 | 347 | createEnv = withSublogger "init" $ do
|
|
0 commit comments