我和serversession-frontend-snap一起使用serversession-backend-acid-state进行会话。
如果我使用内存版本的acid-state运行,一切工作正常:
-- create state container in memory from initial state
acidMem :: IO (AcidStorage SessionMap)
acidMem = AcidStorage <$> openMemoryState emptyState
app :: SnapletInit App App
app = makeSnaplet "app" "An snaplet example application." Nothing $ do
conf <- getSnapletUserConfig
h <- nestSnaplet "" heist $ heistInit "templates"
s <- nestSnaplet "sess"sess $ SS.simpleServerSessionManager acidDisk id通过使用以下命令,我可以成功地使用acid-state的磁盘版本:
acidDisk :: IO (AcidStorage SessionMap)
acidDisk = AcidStorage <$> openLocalState emptyState当我关闭snap时,我的问题出现了;我不知道在哪里可以通过(createCheckpointAndClose . acidState)正确地关闭acid-state。如果没有正确的关机,我将在重新启动快照时出现错误。
我在Main.hs中看到了cleanup函数,但我不明白如何使用它来关闭acid状态。解决这一问题的最佳方法是什么?
编辑:我发现了onUnload,但不能用它包装simpleServerSessionManager。
编辑#2:我已经确定了如何使用onUnload让它与acidDisk一起工作:
ad <- liftIO $ fmap opts . createState =<< acidDisk
s <- nestSnaplet "sess"sess $
SS.initServerSessionManager (return ad)
onUnload (createCheckpointAndClose $ acidState $ storage ad)发布于 2019-06-05 08:41:27
作为参考,我通过获取对酸状态的引用来解决它,然后使用onUnload关闭它:
acidDisk :: IO (AcidStorage SessionMap)
acidDisk = AcidStorage <$> openLocalState emptyState
app :: SnapletInit App App
app = makeSnaplet "app" "An snaplet example application." Nothing $ do
conf <- getSnapletUserConfig
h <- nestSnaplet "" heist $ heistInit "templates"
ad <- liftIO $ fmap opts . createState =<< acidDisk
s <- nestSnaplet "sess"sess $
SS.initServerSessionManager (return ad)
onUnload (createCheckpointAndClose $ acidState $ storage ad)发布于 2019-06-04 14:53:49
如何关闭服务器?如果是通过终止进程,则需要捕获ThreadKilled和/或UserInterrupt异常,如here文档所示
(Snap似乎没有“在强制关闭的情况下”挂钩,也不是它的义务)
否则,您将不得不添加检查点指令作为任何关闭过程的一部分。
https://stackoverflow.com/questions/56398413
复制相似问题