mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
b091c75372
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3421 GitOrigin-RevId: 8802d7e6a360edee62011ef371cc8930f36b25b1
58 lines
1.5 KiB
Haskell
58 lines
1.5 KiB
Haskell
{-# OPTIONS -Wno-redundant-constraints #-}
|
|
|
|
-- | SQLServer helpers.
|
|
module Harness.Backend.Sqlserver
|
|
( livenessCheck,
|
|
run_,
|
|
)
|
|
where
|
|
|
|
import Control.Concurrent
|
|
import Control.Exception
|
|
import Control.Monad.Reader
|
|
import Data.String
|
|
import Database.ODBC.SQLServer qualified as Sqlserver
|
|
import GHC.Stack
|
|
import Harness.Constants as Constants
|
|
import System.Process.Typed
|
|
import Prelude
|
|
|
|
-- | Check that the SQLServer service is live and ready to accept connections.
|
|
livenessCheck :: HasCallStack => IO ()
|
|
livenessCheck = loop Constants.sqlserverLivenessCheckAttempts
|
|
where
|
|
loop 0 = error ("Liveness check failed for SQLServer.")
|
|
loop attempts =
|
|
catch
|
|
( bracket
|
|
(Sqlserver.connect Constants.sqlserverConnectInfo)
|
|
Sqlserver.close
|
|
(const (pure ()))
|
|
)
|
|
( \(_failure :: ExitCodeException) -> do
|
|
threadDelay
|
|
Constants.sqlserverLivenessCheckIntervalMicroseconds
|
|
loop (attempts - 1)
|
|
)
|
|
|
|
-- | Run a plain SQL string against the server, ignore the
|
|
-- result. Just checks for errors.
|
|
run_ :: HasCallStack => String -> IO ()
|
|
run_ query' =
|
|
catch
|
|
( bracket
|
|
(Sqlserver.connect Constants.sqlserverConnectInfo)
|
|
Sqlserver.close
|
|
(\conn -> void (Sqlserver.exec conn (fromString query')))
|
|
)
|
|
( \(e :: SomeException) ->
|
|
error
|
|
( unlines
|
|
[ "SQLServer query error:",
|
|
show e,
|
|
"SQL was:",
|
|
query'
|
|
]
|
|
)
|
|
)
|