@@ -18,6 +18,7 @@ module Cardano.DbSync.OffChain (
18
18
) where
19
19
20
20
import Cardano.BM.Trace (Trace , logInfo )
21
+ import Cardano.Db (runIohkLogging )
21
22
import qualified Cardano.Db as DB
22
23
import Cardano.DbSync.Api
23
24
import Cardano.DbSync.Api.Types (InsertOptions (.. ), SyncEnv (.. ))
@@ -34,6 +35,7 @@ import Control.Concurrent.Class.MonadSTM.Strict (
34
35
import Control.Monad.Trans.Control (MonadBaseControl )
35
36
import Data.Time.Clock.POSIX (POSIXTime )
36
37
import qualified Data.Time.Clock.POSIX as Time
38
+ import Database.Persist.Postgresql (withPostgresqlConn )
37
39
import Database.Persist.Sql (SqlBackend )
38
40
import qualified Network.HTTP.Client as Http
39
41
import Network.HTTP.Client.TLS (tlsManagerSettings )
@@ -167,14 +169,17 @@ runFetchOffChainPoolThread syncEnv = do
167
169
-- if dissable gov is active then don't run voting anchor thread
168
170
when (ioOffChainPoolData iopts) $ do
169
171
logInfo trce " Running Offchain Pool fetch thread"
170
- forever $ do
171
- tDelay
172
- -- load the offChain vote work queue using the db
173
- _ <- runReaderT (loadOffChainPoolWorkQueue trce (envOffChainPoolWorkQueue syncEnv)) (envBackend syncEnv)
174
- poolq <- atomically $ flushTBQueue (envOffChainPoolWorkQueue syncEnv)
175
- manager <- Http. newManager tlsManagerSettings
176
- now <- liftIO Time. getPOSIXTime
177
- mapM_ (queuePoolInsert <=< fetchOffChainPoolData trce manager now) poolq
172
+ runIohkLogging trce $
173
+ withPostgresqlConn (envConnectionString syncEnv) $
174
+ \ backendPool -> liftIO $
175
+ forever $ do
176
+ tDelay
177
+ -- load the offChain vote work queue using the db
178
+ _ <- runReaderT (loadOffChainPoolWorkQueue trce (envOffChainPoolWorkQueue syncEnv)) backendPool
179
+ poolq <- atomically $ flushTBQueue (envOffChainPoolWorkQueue syncEnv)
180
+ manager <- Http. newManager tlsManagerSettings
181
+ now <- liftIO Time. getPOSIXTime
182
+ mapM_ (queuePoolInsert <=< fetchOffChainPoolData trce manager now) poolq
178
183
where
179
184
trce = getTrace syncEnv
180
185
iopts = getInsertOptions syncEnv
@@ -187,14 +192,17 @@ runFetchOffChainVoteThread syncEnv = do
187
192
-- if dissable gov is active then don't run voting anchor thread
188
193
when (ioGov iopts) $ do
189
194
logInfo trce " Running Offchain Vote Anchor fetch thread"
190
- forever $ do
191
- tDelay
192
- -- load the offChain pool work queue using the db
193
- _ <- runReaderT (loadOffChainVoteWorkQueue trce (envOffChainVoteWorkQueue syncEnv)) (envBackend syncEnv)
194
- voteq <- atomically $ flushTBQueue (envOffChainVoteWorkQueue syncEnv)
195
- manager <- Http. newManager tlsManagerSettings
196
- now <- liftIO Time. getPOSIXTime
197
- mapM_ (queueVoteInsert <=< fetchOffChainVoteData trce manager now) voteq
195
+ runIohkLogging trce $
196
+ withPostgresqlConn (envConnectionString syncEnv) $
197
+ \ backendVote -> liftIO $
198
+ forever $ do
199
+ tDelay
200
+ -- load the offChain pool work queue using the db
201
+ _ <- runReaderT (loadOffChainVoteWorkQueue trce (envOffChainVoteWorkQueue syncEnv)) backendVote
202
+ voteq <- atomically $ flushTBQueue (envOffChainVoteWorkQueue syncEnv)
203
+ manager <- Http. newManager tlsManagerSettings
204
+ now <- liftIO Time. getPOSIXTime
205
+ mapM_ (queueVoteInsert <=< fetchOffChainVoteData trce manager now) voteq
198
206
where
199
207
trce = getTrace syncEnv
200
208
iopts = getInsertOptions syncEnv
0 commit comments