2022-11-23 19:40:21 +03:00
|
|
|
module Hasura.PingSources
|
|
|
|
( runPingSources,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Control.Concurrent.Extended qualified as Conc
|
2023-02-14 15:14:33 +03:00
|
|
|
import Data.Environment qualified as Env
|
2022-11-23 19:40:21 +03:00
|
|
|
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 ::
|
2023-02-14 15:14:33 +03:00
|
|
|
Env.Environment ->
|
2022-11-23 19:40:21 +03:00
|
|
|
(String -> IO ()) ->
|
|
|
|
IO SourcePingCache ->
|
|
|
|
IO a
|
2023-02-14 15:14:33 +03:00
|
|
|
runPingSources env pingLog fetchPingCacheIO =
|
2022-11-23 19:40:21 +03:00
|
|
|
forever $ do
|
|
|
|
pingCache <- liftIO fetchPingCacheIO
|
|
|
|
for_ pingCache $ \someSourcePingInfo ->
|
|
|
|
AB.dispatchAnyBackend @Backend
|
|
|
|
someSourcePingInfo
|
|
|
|
\(thisSourcePingInfo :: SourcePingInfo b) ->
|
|
|
|
runPingSource @b
|
2023-02-14 15:14:33 +03:00
|
|
|
env
|
2022-11-23 19:40:21 +03:00
|
|
|
pingLog
|
|
|
|
(_spiName thisSourcePingInfo)
|
|
|
|
(_spiConnection thisSourcePingInfo)
|
|
|
|
|
|
|
|
-- Sleep the thread for a minute
|
|
|
|
liftIO $ Conc.sleep $ seconds 60
|