diff --git a/src/Guide/Server.hs b/src/Guide/Server.hs index 8b351a4..8102e48 100644 --- a/src/Guide/Server.hs +++ b/src/Guide/Server.hs @@ -152,10 +152,8 @@ mainWith config = do -- 'createCheckpoint', etc let prepare = openLocalStateFrom "state/" emptyState finalise db = do - putStrLn "Creating an acid-state checkpoint" - createCheckpoint' db - putStrLn "Closing acid-state" - closeAcidState db + putStrLn "Creating an acid-state checkpoint and closing acid-state" + createCheckpointAndClose' db -- Killing EKG has to be done last, because of -- putStrLn "Killing EKG" diff --git a/src/Guide/ServerStuff.hs b/src/Guide/ServerStuff.hs index 0b1056c..ab7fff4 100644 --- a/src/Guide/ServerStuff.hs +++ b/src/Guide/ServerStuff.hs @@ -33,6 +33,7 @@ module Guide.ServerStuff -- * Other helpers createCheckpoint', + createCheckpointAndClose', ) where @@ -45,6 +46,7 @@ import qualified Web.Spock as Spock import Web.Routing.Combinators (PathState(..)) -- acid-state import Data.Acid as Acid +import Data.Acid.Local as Acid import Guide.Config import Guide.State @@ -316,3 +318,14 @@ createCheckpoint' db = liftIO $ do when wasDirty $ do createArchive db createCheckpoint db + +-- | Like 'createCheckpointAndClose', but doesn't create a checkpoint if +-- there were no changes made. +createCheckpointAndClose' :: MonadIO m => DB -> m () +createCheckpointAndClose' db = liftIO $ do + wasDirty <- Acid.update db UnsetDirty + if wasDirty then do + createArchive db + createCheckpointAndClose db + else do + closeAcidState db