graphql-engine/server/src-lib/Hasura/PingSources.hs
Daniel Harvey 79b50add5e [server] regularly ping selected sources
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6945
GitOrigin-RevId: cad67b121090d4100330067d3d50f575292b4584
2022-11-23 16:41:46 +00:00

33 lines
1017 B
Haskell

module Hasura.PingSources
( runPingSources,
)
where
import Control.Concurrent.Extended qualified as Conc
import Hasura.Prelude
import Hasura.RQL.Types.Backend (Backend (..))
import Hasura.RQL.Types.Source (SourcePingCache, SourcePingInfo (..))
import Hasura.SQL.AnyBackend qualified as AB
-- | A forever running IO loop that performs regular pings for DBs that need it
-- these are used to send a fingerprint to third parties that wish to attribute
-- users to Hasura
runPingSources ::
(String -> IO ()) ->
IO SourcePingCache ->
IO a
runPingSources pingLog fetchPingCacheIO =
forever $ do
pingCache <- liftIO fetchPingCacheIO
for_ pingCache $ \someSourcePingInfo ->
AB.dispatchAnyBackend @Backend
someSourcePingInfo
\(thisSourcePingInfo :: SourcePingInfo b) ->
runPingSource @b
pingLog
(_spiName thisSourcePingInfo)
(_spiConnection thisSourcePingInfo)
-- Sleep the thread for a minute
liftIO $ Conc.sleep $ seconds 60