[notifications] fix error reporting for a job that fails immediately

Related to
#728
parent c010d97a
Pipeline #7291 passed with stages
in 22 minutes and 25 seconds
......@@ -3,6 +3,7 @@ module Gargantext.AsyncTasks
, TaskList
, Storage(..)
, insert
, hasTask
, finish
, focus
-- , asyncTaskTTriggersAppReload
......@@ -78,6 +79,14 @@ insert id task storageBox = modifyTaskBox newStorage storageBox
where
newStorage (Storage s) = Storage $ Map.alter (maybe (Just [ task ]) (\ts -> Just $ A.nub $ A.cons task ts)) id s
hasTask :: GT.NodeID -> Task -> T.Box Storage -> Effect Boolean
hasTask id (GT.WorkerTask { message_id }) storage = do
Storage storage' <- T.read storage
case Map.lookup id storage' of
Nothing -> pure false
Just taskList ->
pure $ A.any (\(GT.WorkerTask { message_id: mId }) -> mId == message_id) taskList
finish :: GT.NodeID -> Task -> T.Box Storage -> Effect Unit
finish id task storage = remove id task storage
......
......@@ -31,6 +31,7 @@ import Gargantext.Components.Lang (Lang(EN))
import Gargantext.Components.Nodes.Corpus.Types (CorpusData)
import Gargantext.Components.Notifications as Notifications
import Gargantext.Components.Notifications.Types as NT
import Gargantext.Config.Utils (handleErrorInAsyncTaskLog)
import Gargantext.Context.Progress (asyncContext, asyncProgress)
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoader)
......@@ -258,9 +259,16 @@ nodeSpanCpt = here.component "nodeSpan" cpt
void $ setTimeout 400 $ T2.reload reload
NT.NUpdateWorkerProgress ji atl -> do
-- TODO Fire this only once!
-- here.log3 "[nodeSpan] update job progress" ji atl
if GT.asyncTaskLogIsFinished atl then pure unit
else
here.log3 "[nodeSpan] update job progress" ji atl
if GT.asyncTaskLogIsFinished atl then do
-- Handle error but only when the task is not already in the storage
-- (we want to avoid reporting the error multiple times, from different places).
-- See e.g. https://gitlab.iscpif.fr/gargantext/purescript-gargantext/issues/728
-- (error is thrown before the task marks any progress)
hasTask <- GAT.hasTask props.id ji boxes.tasks
unless hasTask $ do
handleErrorInAsyncTaskLog boxes.errors atl
else do
GAT.insert props.id ji boxes.tasks
_ -> pure unit
ws <- T.read boxes.wsNotification
......
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