From 33d507286eba02a006a636c009ee48e21f2a4f4d Mon Sep 17 00:00:00 2001 From: iko Date: Mon, 4 Oct 2021 18:30:01 +0300 Subject: [PATCH] Fixed failure state when creating deployments and added sorting direction (#125) * Fixed failure statuses when creating or updating deployments * Added sorting --- octopod-backend/src/Octopod/Server.hs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/octopod-backend/src/Octopod/Server.hs b/octopod-backend/src/Octopod/Server.hs index 596088c..58fda30 100644 --- a/octopod-backend/src/Octopod/Server.hs +++ b/octopod-backend/src/Octopod/Server.hs @@ -30,6 +30,7 @@ import qualified Data.Csv as C import Data.Fixed import Data.Foldable import Data.Functor +import Data.Functor.Contravariant import Data.Generics.Labels () import Data.Generics.Product import Data.IORef @@ -471,7 +472,9 @@ getFullInfo :: m [DeploymentFullInfo] getFullInfo = do AppState {logger = l} <- ask - deploymentsSchema <- runStatement . select $ each deploymentSchema + deploymentsSchema <- + runStatement . select . orderBy (view #updatedAt >$< desc) $ + each deploymentSchema deployments <- forM deploymentsSchema extractDeploymentFullInfo liftBase . logInfo l $ "get deployments: " <> (pack . show $ deployments) return deployments @@ -510,7 +513,7 @@ createH dep = do , createdAt = now , updatedAt = now , archivedAt = litExpr Nothing - , status = litExpr Running + , status = litExpr CreatePending , statusUpdatedAt = now , checkedAt = now , metadata = litExpr (DeploymentMetadata []) @@ -593,12 +596,14 @@ selectDeploymentLogs :: (MonadBaseControl IO m, MonadReader AppState m) => DeploymentName -> m [DeploymentLog] -selectDeploymentLogs dName = (fmap . fmap) extractDeploymentLog . runStatement . select $ do - dls <- each deploymentLogSchema - ds <- each deploymentSchema - where_ $ ds ^. #name ==. litExpr dName - where_ $ dls ^. #deploymentId ==. ds ^. #id_ - pure dls +selectDeploymentLogs dName = (fmap . fmap) extractDeploymentLog . runStatement . select + . orderBy (view #createdAt >$< desc) + $ do + dls <- each deploymentLogSchema + ds <- each deploymentSchema + where_ $ ds ^. #name ==. litExpr dName + where_ $ dls ^. #deploymentId ==. ds ^. #id_ + pure dls data StatusTransitionProcessOutput = StatusTransitionProcessOutput { exitCode :: ExitCode @@ -719,6 +724,7 @@ transitionToStatus dName s = do dep & #status .~ litExpr newS & #updatedAt .~ now + & #statusUpdatedAt .~ now & if newS == Archived then #archivedAt .~ nullify now else id , updateWhere = \() dep -> dep ^. #name ==. litExpr dName , returning = Projection id