Haskell, Yesod and Keter - How can I run a routine periodically (every 5 minutes)?

192 Views Asked by At

There are some database queries I want to run periodically, and according to its state, send notifications to users email and change the state of their accounts. Can I do it within Yesod itself?

1

There are 1 best solutions below

0
On

I moved from Yesod's issue.

Run Handler code at a specific time within yesod · Issue #1529 · yesodweb/yesod


I do not know your complete code. So, this is proposal.

makeApplication :: App -> IO Application
makeApplication foundation = do
    unsafeHandler foundation $
        forkHandler (\_ -> catchError) $ forever $ do -- catchError do not exist
          waitUntil10AM         -- waitUntil10AM do not exist
          getCheckupR
    logWare <- makeLogWare foundation
    -- Create the WAI application and apply middlewares
    appPlain <- toWaiAppPlain foundation
    return $ logWare $ (acceptOverride . autohead . gzip def) appPlain

This code point that use unsafeHandler and forkHandler.

waitUntil10AM

I do not know your timezone, environment, database structure etc, so I want you to write the details yourself. For example, if you put threadDelay in forever and check it once every ten minutes, put the date on which you sent the mail already in the database and call it if you do not send it and it exceeds 10AM.

catchError

Please decide what kind of processing should be done at the time of error.

I would like to handle errors in a way that it would never stop

You can name the function to be passed inside forkHandler and call it again on error.