From cc205596ae55826dcefe51ebaef3227ad72bb3d8 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 13 Oct 2019 22:20:23 +0200 Subject: [PATCH] feat(allocations): allow additional notifications --- src/Jobs/Crontab.hs | 3 ++- src/Jobs/Handler/QueueNotification.hs | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Jobs/Crontab.hs b/src/Jobs/Crontab.hs index a852dcdc7..210fa4cc7 100644 --- a/src/Jobs/Crontab.hs +++ b/src/Jobs/Crontab.hs @@ -338,12 +338,13 @@ determineCrontab = execWriterT $ do _other -> return () doneSince <- lift $ allocationDone nAllocation + whenIsJust doneSince $ \doneSince' -> tell $ HashMap.singleton (JobCtlQueue $ JobQueueNotification NotificationAllocationResults{..}) Cron { cronInitial = CronTimestamp . utcToLocalTimeTZ appTZ $ addUTCTime appNotificationCollateDelay doneSince' - , cronRepeat = CronRepeatNever + , cronRepeat = CronRepeatOnChange , cronRateLimit = appNotificationRateLimit , cronNotAfter = Left appNotificationExpiration } diff --git a/src/Jobs/Handler/QueueNotification.hs b/src/Jobs/Handler/QueueNotification.hs index 8812d2f48..b38c0dcb2 100644 --- a/src/Jobs/Handler/QueueNotification.hs +++ b/src/Jobs/Handler/QueueNotification.hs @@ -198,7 +198,8 @@ determineNotificationCandidates NotificationExamOfficeExamResultsChanged{..} = E.where_ $ examResult E.^. ExamResultId `E.in_` E.valList (Set.toList nExamResults) E.where_ $ examOfficeExamResultAuth (user E.^. UserId) examResult return user -determineNotificationCandidates NotificationAllocationResults{..} = +determineNotificationCandidates notif@NotificationAllocationResults{..} = do + lastExec <- fmap (fmap $ cronLastExecTime . entityVal) . getBy . UniqueCronLastExec . toJSON $ JobQueueNotification notif E.select . E.from $ \user -> do let isStudent = E.exists . E.from $ \application -> E.where_ $ application E.^. CourseApplicationAllocation E.==. E.just (E.val nAllocation) @@ -207,7 +208,19 @@ determineNotificationCandidates NotificationAllocationResults{..} = E.on $ lecturer E.^. LecturerCourse E.==. allocationCourse E.^. AllocationCourseCourse E.&&. allocationCourse E.^. AllocationCourseAllocation E.==. E.val nAllocation E.&&. lecturer E.^. LecturerUser E.==. user E.^. UserId - E.where_ $ isStudent E.||. isLecturer + + wasAllocated t = E.exists . E.from $ \participant -> + E.where_ $ participant E.^. CourseParticipantUser E.==. user E.^. UserId + E.&&. participant E.^. CourseParticipantAllocated E.==. E.just (E.val nAllocation) + E.&&. participant E.^. CourseParticipantRegistration E.>. E.val t + hasAllocations t = E.exists . E.from $ \(lecturer `E.InnerJoin` participant) -> do + E.on $ lecturer E.^. LecturerUser E.==. user E.^. UserId + E.&&. lecturer E.^. LecturerCourse E.==. participant E.^. CourseParticipantCourse + E.where_ $ participant E.^. CourseParticipantAllocated E.==. E.just (E.val nAllocation) + E.&&. participant E.^. CourseParticipantRegistration E.>. E.val t + case lastExec of + Nothing -> E.where_ $ isStudent E.||. isLecturer + Just t -> E.where_ $ wasAllocated t E.||. hasAllocations t return user determineNotificationCandidates NotificationCourseRegistered{..} =