1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-23 12:15:06 +03:00

Use atomic createCheckpointAndClose because atomic = good

This commit is contained in:
Artyom 2017-02-25 16:37:49 +03:00
parent 4530cc6249
commit 3acd358438
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710
2 changed files with 15 additions and 4 deletions

View File

@ -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
-- <https://github.com/tibbe/ekg/issues/62>
putStrLn "Killing EKG"

View File

@ -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