From c33964750d633f3c3ec2076c7fa2a28a4001829e Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Wed, 17 May 2023 09:35:24 +0000 Subject: [PATCH] chore(avs): prepare general background synch job --- src/Jobs/Handler/SynchroniseAvs.hs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Jobs/Handler/SynchroniseAvs.hs b/src/Jobs/Handler/SynchroniseAvs.hs index 119d9ef0a..5fd2807dd 100644 --- a/src/Jobs/Handler/SynchroniseAvs.hs +++ b/src/Jobs/Handler/SynchroniseAvs.hs @@ -3,18 +3,21 @@ -- SPDX-License-Identifier: AGPL-3.0-or-later module Jobs.Handler.SynchroniseAvs - ( dispatchJobSynchroniseAvsId - , dispatchJobSynchroniseAvsUser + ( dispatchJobSynchroniseAvs + , dispatchJobSynchroniseAvsId + , dispatchJobSynchroniseAvsUser ) where import Import +import qualified Data.Conduit.List as C +import Jobs.Queue + import Handler.Utils.Avs - -{- TODO: general AVS synchronisation -dispatchJobSynchroniseLdap :: Natural -> Natural -> Natural -> JobHandler UniWorX -dispatchJobSynchroniseLdap numIterations epoch iteration +-- TODO: JobSynchroniseAllAvs is not yet scheduled in Crontab +dispatchJobSynchroniseAvs :: Natural -> Natural -> Natural -> Maybe UTCTime -> JobHandler UniWorX +dispatchJobSynchroniseAvs numIterations epoch iteration pause = JobHandlerAtomic . runConduit $ readUsers .| filterIteration .| sinkDBJobs where @@ -27,15 +30,14 @@ dispatchJobSynchroniseLdap numIterations epoch iteration userIteration, currentIteration :: Integer userIteration = toInteger (hash epoch `hashWithSalt` userId) `mod` toInteger numIterations currentIteration = toInteger iteration `mod` toInteger numIterations - $logDebugS "SynchroniseLdap" [st|User ##{tshow (fromSqlKey userId)}: sync on #{tshow userIteration}/#{tshow numIterations}, now #{tshow currentIteration}|] + $logDebugS "SynchronisAvs" [st|User ##{tshow (fromSqlKey userId)}: sync on #{tshow userIteration}/#{tshow numIterations}, now #{tshow currentIteration}|] guard $ userIteration == currentIteration - - return $ JobSynchroniseLdapUser userId --} + + return $ JobSynchroniseAvsUser userId pause -dispatchJobSynchroniseAvs :: Either AvsPersonId UserId -> Maybe UTCTime -> JobHandler UniWorX -dispatchJobSynchroniseAvs eauid pause = JobHandlerException $ do +workJobSynchroniseAvs :: Either AvsPersonId UserId -> Maybe UTCTime -> JobHandler UniWorX +workJobSynchroniseAvs eauid pause = JobHandlerException $ do let uniqKey = either UniqueUserAvsId UniqueUserAvsUser eauid runDB (getBy uniqKey) >>= \case Nothing -> return () -- do not create new newers in this background job, only update existing @@ -44,7 +46,7 @@ dispatchJobSynchroniseAvs eauid pause = JobHandlerException $ do | otherwise -> void $ upsertAvsUserById userAvsPersonId -- updates UserAvsLAstSynch dispatchJobSynchroniseAvsId :: AvsPersonId -> Maybe UTCTime -> JobHandler UniWorX -dispatchJobSynchroniseAvsId = dispatchJobSynchroniseAvs . Left +dispatchJobSynchroniseAvsId = workJobSynchroniseAvs . Left dispatchJobSynchroniseAvsUser :: UserId -> Maybe UTCTime -> JobHandler UniWorX -dispatchJobSynchroniseAvsUser = dispatchJobSynchroniseAvs . Right +dispatchJobSynchroniseAvsUser = workJobSynchroniseAvs . Right