Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
f7b46ba2
Verified
Commit
f7b46ba2
authored
Jun 20, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[tasks] implement exponential backoff
This is to avoid bombarding users with task errors.
parent
83bd57b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
8 deletions
+36
-8
Progress.purs
src/Gargantext/Context/Progress.purs
+36
-8
No files found.
src/Gargantext/Context/Progress.purs
View file @
f7b46ba2
...
...
@@ -6,6 +6,7 @@ module Gargantext.Context.Progress
import Gargantext.Prelude
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
...
...
@@ -35,15 +36,17 @@ here :: R2.Here
here = R2.here "Gargantext.Context.Progress"
asyncProgress :: R2.Component AsyncProps
asyncProgress = R2.component
componen
t
componen
t :: R.Component AsyncProps
component = R.hooksComponent "asyncProgressContext
" cpt where
asyncProgress = R2.component
asyncProgressCp
t
asyncProgressCp
t :: R.Component AsyncProps
asyncProgressCpt = R.hooksComponent "asyncProgress
" cpt where
cpt props@{ errors
, onFinish
} children = do
-- States
progress /\ progressBox <- R2.useBox' 0.0
intervalIdRef <- R.useRef (Nothing :: Maybe IntervalId)
-- exponential backoff is used when errors are reported
interval <- T.useBox 1000
-- Methods
let
...
...
@@ -52,6 +55,13 @@ component = R.hooksComponent "asyncProgressContext" cpt where
let rdata = (RX.pick props :: Record QueryProgressData)
eAsyncProgress <- queryProgress rdata
-- exponential backoff in case of errors
liftEffect $ do
case eAsyncProgress of
Left _ -> T.modify_ (_ * 2) interval
Right _ -> T.write_ 1000 interval
interval' <- T.read interval
resetInterval intervalIdRef (Just interval') exec
handleRESTError here errors eAsyncProgress onProgress
onProgress :: AsyncProgress -> Aff Unit
...
...
@@ -64,9 +74,10 @@ component = R.hooksComponent "asyncProgressContext" cpt where
(status == GT.IsKilled) ||
(status == GT.IsFailure)
then do
case R.readRef intervalIdRef of
Nothing -> R.nothing
Just iid -> clearInterval iid
resetInterval intervalIdRef Nothing exec
-- case R.readRef intervalIdRef of
-- Nothing -> R.nothing
-- Just iid -> clearInterval iid
handleErrorInAsyncProgress errors value
onFinish unit
else
...
...
@@ -74,8 +85,9 @@ component = R.hooksComponent "asyncProgressContext" cpt where
-- Hooks
useFirstEffect' do
intervalId <- setInterval 1000 $ exec unit
R.setRef intervalIdRef $ Just intervalId
resetInterval intervalIdRef (Just 1000) exec
-- intervalId <- setInterval interval' $ exec unit
-- R.setRef intervalIdRef $ Just intervalId
-- Render
pure $
...
...
@@ -83,5 +95,21 @@ component = R.hooksComponent "asyncProgressContext" cpt where
R.provideContext asyncContext (progress)
children
resetInterval :: R.Ref (Maybe IntervalId) -> Maybe Int -> (Unit -> Effect Unit) -> Effect Unit
resetInterval ref mInt exec = do
case R.readRef ref /\ mInt of
Nothing /\ Nothing ->
pure unit
Nothing /\ Just interval' -> do
intervalId <- setInterval interval' $ exec unit
R.setRef ref $ Just intervalId
Just iid /\ Nothing -> do
clearInterval iid
R.setRef ref Nothing
Just iid /\ Just interval' -> do
clearInterval iid
intervalId <- setInterval interval' $ exec unit
R.setRef ref $ Just intervalId
asyncContext :: R.Context (Number)
asyncContext = R.createContext 0.0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment