mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
342391f39d
This upgrades the version of Ormolu required by the HGE repository to v0.5.0.1, and reformats all code accordingly. Ormolu v0.5 reformats code that uses infix operators. This is mostly useful, adding newlines and indentation to make it clear which operators are applied first, but in some cases, it's unpleasant. To make this easier on the eyes, I had to do the following: * Add a few fixity declarations (search for `infix`) * Add parentheses to make precedence clear, allowing Ormolu to keep everything on one line * Rename `relevantEq` to `(==~)` in #6651 and set it to `infix 4` * Add a few _.ormolu_ files (thanks to @hallettj for helping me get started), mostly for Autodocodec operators that don't have explicit fixity declarations In general, I think these changes are quite reasonable. They mostly affect indentation. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6675 GitOrigin-RevId: cd47d87f1d089fb0bc9dcbbe7798dbceedcd7d83
70 lines
2.2 KiB
Haskell
70 lines
2.2 KiB
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
module Hasura.Server.CheckUpdates
|
|
( checkForUpdates,
|
|
)
|
|
where
|
|
|
|
import CI qualified
|
|
import Control.Concurrent.Extended qualified as C
|
|
import Control.Exception (try)
|
|
import Control.Lens
|
|
import Data.Aeson qualified as A
|
|
import Data.Aeson.Casing qualified as A
|
|
import Data.Aeson.TH qualified as A
|
|
import Data.Either (fromRight)
|
|
import Data.Text qualified as T
|
|
import Data.Text.Conversions (toText)
|
|
import Hasura.HTTP
|
|
import Hasura.Logging (LoggerCtx (..))
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Version (Version, currentVersion)
|
|
import Network.HTTP.Client qualified as HTTP
|
|
import Network.URI.Encode qualified as URI
|
|
import Network.Wreq qualified as Wreq
|
|
import System.Log.FastLogger qualified as FL
|
|
|
|
newtype UpdateInfo = UpdateInfo
|
|
{ _uiLatest :: Version
|
|
}
|
|
deriving (Show)
|
|
|
|
-- note that this is erroneous and should drop three characters or use
|
|
-- aesonPrefix, but needs to remain like this for backwards compatibility
|
|
$(A.deriveJSON (A.aesonDrop 2 A.snakeCase) ''UpdateInfo)
|
|
|
|
checkForUpdates :: LoggerCtx a -> HTTP.Manager -> IO void
|
|
checkForUpdates (LoggerCtx loggerSet _ _ _) manager = do
|
|
let options = wreqOptions manager []
|
|
url <- getUrl
|
|
forever $ do
|
|
resp <- try $ Wreq.getWith options $ T.unpack url
|
|
case resp of
|
|
Left ex -> ignoreHttpErr ex
|
|
Right bs -> do
|
|
UpdateInfo latestVersion <- decodeResp $ bs ^. Wreq.responseBody
|
|
when (latestVersion /= currentVersion) $
|
|
FL.pushLogStrLn loggerSet $
|
|
FL.toLogStr $
|
|
updateMsg latestVersion
|
|
|
|
C.sleep $ days 1
|
|
where
|
|
updateMsg v = "Update: A new version is available: " <> toText v
|
|
getUrl = do
|
|
let buildUrl agent =
|
|
"https://releases.hasura.io/graphql-engine?agent="
|
|
<> agent
|
|
<> "&version="
|
|
<> URI.encodeText (toText currentVersion)
|
|
ciM <- CI.getCI
|
|
return . buildUrl $ case ciM of
|
|
Nothing -> "server"
|
|
Just ci -> "server-" <> T.toLower (tshow ci)
|
|
|
|
-- ignoring if there is any error in response and returning the current version
|
|
decodeResp = pure . fromRight (UpdateInfo currentVersion) . A.eitherDecode
|
|
|
|
ignoreHttpErr :: HTTP.HttpException -> IO ()
|
|
ignoreHttpErr _ = return ()
|