yesod

How do I implement a shutdown command in a WAI server?

China☆狼群 提交于 2019-12-03 09:36:34
问题 I'd like to implement a 'graceful shutdown' command for my webapp (as opposed to my first instinct, which is to just ask people to kill the process) My first two attempts consisted of liftIO exitSuccess E.yield (responseLBS statusOK [G.contentType "text/plain"] "") E.EOF Both of which just cheerfully returned a result to the client and continued listening. Is there anything an application can do to kill the server? Is this even a reasonable thing to want to do? I confess I don't have a very

Correct way to do a “join” in persist with yesod

我只是一个虾纸丫 提交于 2019-12-03 07:45:25
Consider the models: Player name Text nick Text email Text Maybe phone Text Maybe note Textarea Maybe minutes Int Maybe deriving Table name Text game Text pointsHour Int seats Int Maybe description Text Maybe deriving GamingSession start UTCTime end UTCTime Maybe player PlayerId table TableId seat Int Maybe deriving and the function getGamingSessionsR :: Handler RepHtml getGamingSessionsR = do sessions <- runDB $ selectList [GamingSessionEnd ==. Nothing] [Desc GamingSessionTable] defaultLayout $(widgetFile ("opensessions")) how would one go about getting all of the Player names for each of the

Efficient large file upload with Yesod

白昼怎懂夜的黑 提交于 2019-12-03 07:24:50
问题 I want to implement large file upload with my Yesod application. Right now I have: module Handler.File where import Import import System.Random import System.FilePath import Control.Monad import qualified Data.ByteString.Lazy as LBS import qualified Data.Text.Encoding -- upload uploadDirectory :: FilePath -- FIXME: make this configurable uploadDirectory = "incoming" randomFileName :: IO FilePath randomFileName = do fname'base <- replicateM 20 (randomRIO ('a','z')) let fname = uploadDirectory

How can I get esqueleto to generate an SQL string for me?

亡梦爱人 提交于 2019-12-03 06:26:02
问题 How can I get esqueleto to generate an SQL string from a from statement? The documentation of toRawSql says that "you may just turn on query logging of persistent". I tried all possible forms of MonadLogger that I could understand, but it never printed any SQL. The same documentation also says "manually using this function ... is possible but tedious". However, no constructors of the type, nor any functions returning values of the type, QueryType are exported. I managed to get around this by

Exceptions in Yesod

有些话、适合烂在心里 提交于 2019-12-03 03:23:22
问题 I had made a daemon that used a very primitive form of ipc (telnet and send a String that had certain words in a certain order). I snapped out of it and am now using JSON to pass messages to a Yesod server. However, there were some things I really liked about my design, and I'm not sure what my choices are now. Here's what I was doing: buildManager :: Phase -> IO () buildManager phase = do let buildSeq = findSeq phase jid = JobID $ pack "8" config = MkConfig $ Just jid flip C.catch

How do I implement a shutdown command in a WAI server?

雨燕双飞 提交于 2019-12-02 22:36:52
I'd like to implement a 'graceful shutdown' command for my webapp (as opposed to my first instinct, which is to just ask people to kill the process) My first two attempts consisted of liftIO exitSuccess E.yield (responseLBS statusOK [G.contentType "text/plain"] "") E.EOF Both of which just cheerfully returned a result to the client and continued listening. Is there anything an application can do to kill the server? Is this even a reasonable thing to want to do? I confess I don't have a very strong understanding of iteratee, only enough to know that I can consume my input and that Iteratee is a

How can I get esqueleto to generate an SQL string for me?

懵懂的女人 提交于 2019-12-02 19:52:54
How can I get esqueleto to generate an SQL string from a from statement? The documentation of toRawSql says that "you may just turn on query logging of persistent". I tried all possible forms of MonadLogger that I could understand, but it never printed any SQL. The same documentation also says "manually using this function ... is possible but tedious". However, no constructors of the type, nor any functions returning values of the type, QueryType are exported. I managed to get around this by noticing that QueryType is a newtype and using unsafeCoerce ! I was also forced to provide a Connection

Exceptions in Yesod

◇◆丶佛笑我妖孽 提交于 2019-12-02 16:54:25
I had made a daemon that used a very primitive form of ipc (telnet and send a String that had certain words in a certain order). I snapped out of it and am now using JSON to pass messages to a Yesod server. However, there were some things I really liked about my design, and I'm not sure what my choices are now. Here's what I was doing: buildManager :: Phase -> IO () buildManager phase = do let buildSeq = findSeq phase jid = JobID $ pack "8" config = MkConfig $ Just jid flip C.catch exceptionHandler $ runReaderT (sequence_ $ buildSeq <*> stages) config -- ^^ I would really like to keep the

Capturing Persistent Relations in a Form

僤鯓⒐⒋嵵緔 提交于 2019-12-02 04:31:23
I have defined a one-to-many relationship in Persistent but could not figure out how to create a form that can take one of the foreign keys as input. Simplifying my use case to something like this: Person name String Car personId PersonId name Text type Text Now when I try to generate a Form for Car, what should be the field type for personId? I tried something like this but get an error: entryForm :: Maybe Car -> Form Car entryForm car = renderDivs $ Car <$> areq personIdField "Person" Nothing <*> areq textField "Car Name" ( carName <$> car) <*> areq textField "Type" ( carType <$> car) When I

Extracting database field values inside a Handler

大兔子大兔子 提交于 2019-12-02 03:51:22
问题 I would like to extract a database field (Text) and pass it as an argument to another function from a Handler. However, I run into Type errors. Completely made up example so may feel a bit contrived but should illustrate the issue I am having. Person name Text Car personId PersonId name Text type Text I would like to get a Car entity and then find the corresponding Person. Get his name and then pass it as an argument. Something like: data MyD = MyD { input1 :: Int} entryForm :: Text -> Form