chore(avs): prepare general background synch job
This commit is contained in:
parent
06e71f6552
commit
c33964750d
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user