mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
79b50add5e
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6945 GitOrigin-RevId: cad67b121090d4100330067d3d50f575292b4584
33 lines
1017 B
Haskell
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
|