2022-11-23 19:40:21 +03:00
|
|
|
module Hasura.Backends.Postgres.Instances.PingSource
|
|
|
|
( runCockroachDBPing,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2023-02-14 15:14:33 +03:00
|
|
|
import Data.Environment qualified as Env
|
2022-11-23 19:40:21 +03:00
|
|
|
import Data.Text qualified as T
|
|
|
|
import Database.PG.Query qualified as PG
|
|
|
|
import Hasura.Backends.Postgres.Connection qualified as PG
|
|
|
|
import Hasura.Backends.Postgres.Connection.Connect (withPostgresDB)
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.Types.Common (SourceName, sourceNameToText)
|
|
|
|
import Hasura.Server.Version
|
|
|
|
|
|
|
|
runCockroachDBPing ::
|
2023-02-14 15:14:33 +03:00
|
|
|
Env.Environment ->
|
2022-11-23 19:40:21 +03:00
|
|
|
(String -> IO ()) ->
|
|
|
|
SourceName ->
|
|
|
|
PG.PostgresConnConfiguration ->
|
|
|
|
IO ()
|
2023-02-14 15:14:33 +03:00
|
|
|
runCockroachDBPing env pingLog sourceName sourceConnection = do
|
2022-11-23 19:40:21 +03:00
|
|
|
let versionMessage = "hasura-graphql-engine-version=" <> tshow currentVersion
|
|
|
|
query = PG.fromText ("select 1 /* " <> versionMessage <> " */")
|
2023-02-14 15:14:33 +03:00
|
|
|
result <- withPostgresDB env sourceConnection $ do
|
2022-11-23 19:40:21 +03:00
|
|
|
PG.discardQE PG.dmlTxErrorHandler query () False
|
|
|
|
case result of
|
|
|
|
Left _ ->
|
|
|
|
pingLog ("Ping for " <> T.unpack (sourceNameToText sourceName) <> " failed")
|
|
|
|
Right _ ->
|
|
|
|
pingLog ("Ping for " <> T.unpack (sourceNameToText sourceName) <> " succeeded")
|