1 module Gargantext.Prelude.Job where
6 import Gargantext.Prelude
8 import Gargantext.API.Admin.Orchestrator.Types (JobLog(..))
11 jobLogInit :: Int -> JobLog
13 JobLog { _scst_succeeded = Just 0
14 , _scst_remaining = Just rem
15 , _scst_failed = Just 0
16 , _scst_events = Just [] }
18 jobLogSuccess :: JobLog -> JobLog
19 jobLogSuccess (JobLog { _scst_succeeded = mSucc
20 , _scst_remaining = mRem
21 , _scst_failed = mFail
22 , _scst_events = evt }) =
23 JobLog { _scst_succeeded = (+ 1) <$> mSucc
24 , _scst_remaining = (\x -> x - 1) <$> mRem
25 , _scst_failed = mFail
26 , _scst_events = evt }
29 jobLogFail :: JobLog -> JobLog
30 jobLogFail (JobLog { _scst_succeeded = mSucc
31 , _scst_remaining = mRem
32 , _scst_failed = mFail
33 , _scst_events = evt }) =
34 JobLog { _scst_succeeded = mSucc
35 , _scst_remaining = (\x -> x - 1) <$> mRem
36 , _scst_failed = (+ 1) <$> mFail
37 , _scst_events = evt }
39 runJobLog :: MonadBase IO m => Int -> (JobLog -> m ()) -> m (m (), m (), m JobLog)
40 runJobLog num logStatus = do
41 jlRef <- liftBase $ newIORef $ jobLogInit num
43 return (logRefF jlRef, logRefSuccessF jlRef, getRefF jlRef)
47 jl <- liftBase $ readIORef ref
49 logRefSuccessF ref = do
50 jl <- liftBase $ readIORef ref
51 let jl' = jobLogSuccess jl
52 liftBase $ writeIORef ref jl'
55 liftBase $ readIORef ref