[job] fixes to addMoreSteps for jobs, tests included

parent b298195d
Pipeline #7762 passed with stages
in 47 minutes and 16 seconds
...@@ -23,7 +23,7 @@ module Gargantext.API.Job ( ...@@ -23,7 +23,7 @@ module Gargantext.API.Job (
, addWarningEvent , addWarningEvent
) where ) where
import Control.Lens (over, _Just) import Control.Lens ((%~), over, _Just)
import Data.Text qualified as T import Data.Text qualified as T
import Gargantext.API.Admin.Orchestrator.Types import Gargantext.API.Admin.Orchestrator.Types
import Gargantext.Prelude import Gargantext.Prelude
...@@ -66,7 +66,12 @@ jobLogComplete jl = ...@@ -66,7 +66,12 @@ jobLogComplete jl =
& over scst_remaining (const (Just 0)) & over scst_remaining (const (Just 0))
jobLogAddMore :: Int -> JobLog -> JobLog jobLogAddMore :: Int -> JobLog -> JobLog
jobLogAddMore moreSteps jl = jl & over (scst_remaining . _Just) (+ moreSteps) jobLogAddMore moreSteps jl =
jl & scst_remaining %~ (maybe (Just 0) Just)
& scst_succeeded %~ (maybe (Just 0) Just)
& scst_failed %~ (maybe (Just 0) Just)
& scst_events %~ (maybe (Just []) Just)
& (scst_remaining . _Just) %~ (+ moreSteps)
jobLogFailures :: Int -> JobLog -> JobLog jobLogFailures :: Int -> JobLog -> JobLog
jobLogFailures n jl = over (scst_failed . _Just) (+ n) $ jobLogFailures n jl = over (scst_failed . _Just) (+ n) $
......
...@@ -224,7 +224,7 @@ updateJobProgress (WorkerJobHandle (ji@JobInfo { _ji_message_id })) f = do ...@@ -224,7 +224,7 @@ updateJobProgress (WorkerJobHandle (ji@JobInfo { _ji_message_id })) f = do
Just wjs -> do Just wjs -> do
(CET.ce_notify $ CET.UpdateWorkerProgress ji (_wjs_job_log wjs)) (CET.ce_notify $ CET.UpdateWorkerProgress ji (_wjs_job_log wjs))
`CES.catch` (\(e :: SomeException) -> `CES.catch` (\(e :: SomeException) ->
$(logLocM) ERROR $ T.pack $ displayException e) $(logLocM) WARNING $ T.pack $ displayException e)
where where
updateState mwjs = updateState mwjs =
let initJobLog = let initJobLog =
......
...@@ -354,3 +354,28 @@ testMarkProgress = do ...@@ -354,3 +354,28 @@ testMarkProgress = do
] ]
} }
let msgId2 = (fromJust $ Aeson.decode "2") :: BT.MessageId PGMQ.PGMQBroker
let hdl2 = WorkerJobHandle { _w_job_info = JobInfo { _ji_message_id = msgId2
, _ji_mNode_id = Nothing } }
addMoreSteps 11 hdl2
jl7 <- getLatestJobStatus hdl2
liftBase $ jl7 `shouldBe` JobLog { _scst_succeeded = Just 0
, _scst_failed = Just 0
, _scst_remaining = Just 11
, _scst_events = Just []
}
markStarted 1 hdl2
jl8 <- getLatestJobStatus hdl2
liftBase $ jl8 `shouldBe` JobLog { _scst_succeeded = Just 0
, _scst_failed = Just 0
, _scst_remaining = Just 1
, _scst_events = Just []
}
addMoreSteps 11 hdl2
jl9 <- getLatestJobStatus hdl2
liftBase $ jl9 `shouldBe` JobLog { _scst_succeeded = Just 0
, _scst_failed = Just 0
, _scst_remaining = Just 12
, _scst_events = Just []
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment