chore(avs): towards #124 add jobworker for AVS licence synch (WIP)
This commit is contained in:
parent
d209a110e8
commit
000d8100db
@ -7,10 +7,12 @@ module Jobs.Handler.SynchroniseAvs
|
|||||||
-- , dispatchJobSynchroniseAvsId
|
-- , dispatchJobSynchroniseAvsId
|
||||||
-- , dispatchJobSynchroniseAvsUser
|
-- , dispatchJobSynchroniseAvsUser
|
||||||
, dispatchJobSynchroniseAvsQueue
|
, dispatchJobSynchroniseAvsQueue
|
||||||
|
, dispatchJobSynchroniseAvsLicences
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
|
|
||||||
|
import qualified Data.Text as Text
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import qualified Data.Conduit.List as C
|
import qualified Data.Conduit.List as C
|
||||||
|
|
||||||
@ -128,3 +130,30 @@ dispatchJobSynchroniseAvsQueue = JobHandlerException $ do
|
|||||||
discernJob accs ( _ , E.Value (Just api), E.Value True ) = accs & over _2 (Set.insert api)
|
discernJob accs ( _ , E.Value (Just api), E.Value True ) = accs & over _2 (Set.insert api)
|
||||||
discernJob accs (E.Value uid, E.Value Nothing , E.Value True ) = accs & over _1 (Set.insert uid)
|
discernJob accs (E.Value uid, E.Value Nothing , E.Value True ) = accs & over _1 (Set.insert uid)
|
||||||
discernJob accs ( _ , _ , E.Value False ) = accs
|
discernJob accs ( _ , _ , E.Value False ) = accs
|
||||||
|
|
||||||
|
|
||||||
|
-----------------
|
||||||
|
-- AVS Licences
|
||||||
|
|
||||||
|
dispatchJobSynchroniseAvsLicences :: JobHandler UniWorX
|
||||||
|
-- dispatchJobSynchroniseAvsLicences = error "TODO"
|
||||||
|
dispatchJobSynchroniseAvsLicences = JobHandlerException $ do -- when (synchLevel > 0) $ do
|
||||||
|
let synchLevel = 0 -- SynchLevel corresponds to tables of ProblemAvsSynchR: 4=top grant R, 3= reduce R->F, 2= grant F, 1= revoke F
|
||||||
|
-- TODO: turn level into a setting
|
||||||
|
-- TODO: enable a cron job by setting
|
||||||
|
procLic :: AvsLicence -> Bool -> Set AvsPersonId -> Handler ()
|
||||||
|
procLic aLic up apids
|
||||||
|
| n <- Set.size apids, n > 0 = do
|
||||||
|
let subtype = Text.cons (bool '↧' '↥' up) $ Text.singleton $ licence2char aLic
|
||||||
|
logit errm = runDB $ logInterface' "AVS" subtype False (isJust errm) (Just n) (fromMaybe "Automatic synch" errm)
|
||||||
|
catchAllAvs = flip catch (\err -> logit (Just $ tshow (err :: SomeException)) >> return (-1))
|
||||||
|
oks <- catchAllAvs $ setLicencesAvs $ Set.map (AvsPersonLicence aLic) apids
|
||||||
|
when (oks > 0) $ logit $ toMaybe (oks /= n) [st|Only #{tshow oks}/#{tshow n} licence changes accepted by AVS|]
|
||||||
|
| otherwise = return ()
|
||||||
|
|
||||||
|
AvsLicenceDifferences{..} <- retrieveDifferingLicences
|
||||||
|
when (synchLevel >= 4) $ procLic AvsLicenceRollfeld True avsLicenceDiffGrantRollfeld --grant Rollfeld
|
||||||
|
when (synchLevel >= 3) $ procLic AvsLicenceVorfeld False avsLicenceDiffRevokeRollfeld --downgrade Rollfeld -> Vorfeld
|
||||||
|
when (synchLevel >= 2) $ procLic AvsLicenceVorfeld True avsLicenceDiffGrantVorfeld --grant Vorfeld
|
||||||
|
when (synchLevel >= 1) $ procLic AvsNoLicence False avsLicenceDiffRevokeAll --revoke Vorfeld & Rollfeld
|
||||||
|
|
||||||
|
|||||||
@ -109,6 +109,7 @@ data Job
|
|||||||
-- , jSynchAfter :: Maybe Day
|
-- , jSynchAfter :: Maybe Day
|
||||||
-- }
|
-- }
|
||||||
| JobSynchroniseAvsQueue
|
| JobSynchroniseAvsQueue
|
||||||
|
| JobSynchroniseAvsLicences
|
||||||
| JobChangeUserDisplayEmail { jUser :: UserId
|
| JobChangeUserDisplayEmail { jUser :: UserId
|
||||||
, jDisplayEmail :: UserEmail
|
, jDisplayEmail :: UserEmail
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user