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
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
module Jobs.Handler.SynchroniseAvs
|
module Jobs.Handler.SynchroniseAvs
|
||||||
( dispatchJobSynchroniseAvsId
|
( dispatchJobSynchroniseAvs
|
||||||
, dispatchJobSynchroniseAvsUser
|
, dispatchJobSynchroniseAvsId
|
||||||
|
, dispatchJobSynchroniseAvsUser
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
|
|
||||||
|
import qualified Data.Conduit.List as C
|
||||||
|
import Jobs.Queue
|
||||||
|
|
||||||
import Handler.Utils.Avs
|
import Handler.Utils.Avs
|
||||||
|
|
||||||
|
-- TODO: JobSynchroniseAllAvs is not yet scheduled in Crontab
|
||||||
{- TODO: general AVS synchronisation
|
dispatchJobSynchroniseAvs :: Natural -> Natural -> Natural -> Maybe UTCTime -> JobHandler UniWorX
|
||||||
dispatchJobSynchroniseLdap :: Natural -> Natural -> Natural -> JobHandler UniWorX
|
dispatchJobSynchroniseAvs numIterations epoch iteration pause
|
||||||
dispatchJobSynchroniseLdap numIterations epoch iteration
|
|
||||||
= JobHandlerAtomic . runConduit $
|
= JobHandlerAtomic . runConduit $
|
||||||
readUsers .| filterIteration .| sinkDBJobs
|
readUsers .| filterIteration .| sinkDBJobs
|
||||||
where
|
where
|
||||||
@ -27,15 +30,14 @@ dispatchJobSynchroniseLdap numIterations epoch iteration
|
|||||||
userIteration, currentIteration :: Integer
|
userIteration, currentIteration :: Integer
|
||||||
userIteration = toInteger (hash epoch `hashWithSalt` userId) `mod` toInteger numIterations
|
userIteration = toInteger (hash epoch `hashWithSalt` userId) `mod` toInteger numIterations
|
||||||
currentIteration = toInteger iteration `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
|
guard $ userIteration == currentIteration
|
||||||
|
|
||||||
return $ JobSynchroniseLdapUser userId
|
return $ JobSynchroniseAvsUser userId pause
|
||||||
-}
|
|
||||||
|
|
||||||
|
|
||||||
dispatchJobSynchroniseAvs :: Either AvsPersonId UserId -> Maybe UTCTime -> JobHandler UniWorX
|
workJobSynchroniseAvs :: Either AvsPersonId UserId -> Maybe UTCTime -> JobHandler UniWorX
|
||||||
dispatchJobSynchroniseAvs eauid pause = JobHandlerException $ do
|
workJobSynchroniseAvs eauid pause = JobHandlerException $ do
|
||||||
let uniqKey = either UniqueUserAvsId UniqueUserAvsUser eauid
|
let uniqKey = either UniqueUserAvsId UniqueUserAvsUser eauid
|
||||||
runDB (getBy uniqKey) >>= \case
|
runDB (getBy uniqKey) >>= \case
|
||||||
Nothing -> return () -- do not create new newers in this background job, only update existing
|
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
|
| otherwise -> void $ upsertAvsUserById userAvsPersonId -- updates UserAvsLAstSynch
|
||||||
|
|
||||||
dispatchJobSynchroniseAvsId :: AvsPersonId -> Maybe UTCTime -> JobHandler UniWorX
|
dispatchJobSynchroniseAvsId :: AvsPersonId -> Maybe UTCTime -> JobHandler UniWorX
|
||||||
dispatchJobSynchroniseAvsId = dispatchJobSynchroniseAvs . Left
|
dispatchJobSynchroniseAvsId = workJobSynchroniseAvs . Left
|
||||||
|
|
||||||
dispatchJobSynchroniseAvsUser :: UserId -> Maybe UTCTime -> JobHandler UniWorX
|
dispatchJobSynchroniseAvsUser :: UserId -> Maybe UTCTime -> JobHandler UniWorX
|
||||||
dispatchJobSynchroniseAvsUser = dispatchJobSynchroniseAvs . Right
|
dispatchJobSynchroniseAvsUser = workJobSynchroniseAvs . Right
|
||||||
|
|||||||
Reference in New Issue
Block a user