My build process requires access to various services, such as, Postgres, Redis, and ElasticSearch. Taking Postgres as an example, I wrote the following "oracle":
data PostgresVersion = PostgresVersion deriving (Show, Typeable, Eq, Hashable, Binary, NFData, Generic)
type instance RuleResult PostgresVersion = String
shakeArgs shakeOptions{..} $ do
want [..]
addOracle $ \PostgresVersion -> do
fromStdout <$> cmd (AddEnv "PGPASSWORD" "REDACTED") ["psql", "-qAt", "-U", "pguser", "-h", "localhost", "dbname", "-c", "show server_version"]
Apart from ensuring that Postgres is running it also captures the version number which can be an extra assertion in the build process.
However, how do I handle the case where Postgres is NOT running? Should I use the standard Haskell try
/catch
to deal with it and start Postgres? Or should starting/stopping services be out-of-scope for a "Shakefile"?