module Jobs.Handler.DistributeCorrections
  ( dispatchJobDistributeCorrections
  ) where

import Import

import Jobs.Queue

import Control.Monad.Trans.Reader (mapReaderT)

import Handler.Utils.Submission

import qualified Data.Set as Set


dispatchJobDistributeCorrections :: SheetId
                                 -> Handler ()
dispatchJobDistributeCorrections jSheet = runDBJobs $ do
  (_, unassigned) <- mapReaderT lift $ assignSubmissions jSheet Nothing
  unless (Set.null unassigned) $
    queueDBJob . JobQueueNotification $ NotificationCorrectionsNotDistributed jSheet
