module Jobs.Handler.PruneInvitations
  ( dispatchJobPruneInvitations
  ) where

import Import

import Database.Persist.Sql (deleteWhereCount)

dispatchJobPruneInvitations :: Handler ()
dispatchJobPruneInvitations = do
  now <- liftIO getCurrentTime
  n <- runDB $ deleteWhereCount [ InvitationExpiresAt <. Just now ]
  $logInfoS "PruneInvitations" [st|Deleted #{n} expired invitations|]