当我启动yesod应用程序时,我创建了一个与rabbitmq服务器的连接,我将其存储在App
数据类型中,以便在请求期间访问。当我部署新版本的应用程序或重新启动我的服务器时,我想优雅地关闭此连接。有点像:
import System.Posix.Signals(sigTERM, installHandler, Handler(..))
appMain :: IO ()
appMain = do
settings <- loadAppSettingsArgs [configSettingsYmlValue] useEnv
foundation <- makeFoundation settings
app <- makeApplication foundation
--install shutdown handler here
installHandler sigTERM (Catch (closeConnection (rabbitmqConn app))) Nothing
runSettings (warpSettings foundation) app
然而,如果我这样做,这个过程根本不会退出(而heroku最终会发送一个SIGKILL。所以我可以做到
import System.Posix.Signals(sigTERM, installHandler, Handler(..))
import System.Exit(exitSuccess)
appMain :: IO ()
appMain = do
settings <- loadAppSettingsArgs [configSettingsYmlValue] useEnv
foundation <- makeFoundation settings
app <- makeApplication foundation
--install shutdown handler here, this time exit the process after we close the connection
installHandler sigTERM (Catch ((closeConnection $ rabbitmqConn conn) >> exitSuccess)) Nothing
runSettings (warpSettings foundation) app
但是,我担心如果我在错误的地方执行此操作,我可能会退出应用程序并阻止其他处理程序运行(并阻止其他内容正常关闭)。我想知道我的yesod应用程序中是否有一个地方我应该添加适合框架其余部分的这类代码。