Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CloWM UI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computational Metagenomics
CloWM
CloWM UI
Commits
a7f4538f
Verified
Commit
a7f4538f
authored
1 year ago
by
Daniel Göbel
Browse files
Options
Downloads
Patches
Plain Diff
Use exponential backoff when polling running executions
#85
parent
e078e13b
No related branches found
No related tags found
2 merge requests
!84
Remove development branch
,
!81
Resolve "Use exponential backoff when polling running workflow executions"
Pipeline
#40305
passed
1 year ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/BackoffStrategy.ts
+70
-0
70 additions, 0 deletions
src/utils/BackoffStrategy.ts
src/views/workflows/ListWorkflowExecutionsView.vue
+33
-11
33 additions, 11 deletions
src/views/workflows/ListWorkflowExecutionsView.vue
with
103 additions
and
11 deletions
src/utils/BackoffStrategy.ts
0 → 100644
+
70
−
0
View file @
a7f4538f
abstract
class
BackoffStrategy
{
protected
currentVal
:
number
;
protected
iteration
:
number
;
protected
reachedMax
:
boolean
;
protected
maxValue
:
number
;
constructor
(
maxValue
?:
number
)
{
this
.
currentVal
=
0
;
this
.
iteration
=
0
;
this
.
reachedMax
=
false
;
this
.
maxValue
=
maxValue
??
300
;
}
protected
abstract
computeNextValue
():
number
;
public
reset
()
{
this
.
iteration
=
0
;
this
.
currentVal
=
0
;
this
.
reachedMax
=
false
;
}
public
*
generator
():
Generator
<
number
>
{
while
(
true
)
{
this
.
iteration
++
;
if
(
this
.
reachedMax
)
{
yield
this
.
maxValue
;
}
else
{
this
.
currentVal
=
this
.
computeNextValue
();
if
(
0
<
this
.
maxValue
&&
this
.
maxValue
<
this
.
currentVal
)
{
this
.
reachedMax
=
true
;
yield
this
.
maxValue
;
}
else
{
yield
this
.
currentVal
;
}
}
}
}
}
export
class
ExponentialBackoff
extends
BackoffStrategy
{
protected
computeNextValue
():
number
{
return
2
<<
(
this
.
iteration
-
1
);
}
}
export
class
NoBackoff
extends
BackoffStrategy
{
private
readonly
constantValue
:
number
;
constructor
(
constantValue
?:
number
)
{
super
();
this
.
constantValue
=
constantValue
??
30
;
}
protected
computeNextValue
():
number
{
return
this
.
constantValue
;
}
}
export
class
LinearBackoff
extends
BackoffStrategy
{
private
readonly
backoff
:
number
;
constructor
(
backoff
?:
number
)
{
super
();
this
.
backoff
=
backoff
??
5
;
}
protected
computeNextValue
():
number
{
return
this
.
currentVal
+
this
.
backoff
;
}
}
This diff is collapsed.
Click to expand it.
src/views/workflows/ListWorkflowExecutionsView.vue
+
33
−
11
View file @
a7f4538f
...
...
@@ -8,12 +8,14 @@ import DeleteModal from "@/components/modals/DeleteModal.vue";
import
{
useWorkflowStore
}
from
"
@/stores/workflows
"
;
import
{
useWorkflowExecutionStore
}
from
"
@/stores/workflowExecutions
"
;
import
ParameterModal
from
"
@/components/workflows/modals/ParameterModal.vue
"
;
import
{
ExponentialBackoff
}
from
"
@/utils/BackoffStrategy
"
;
const
workflowRepository
=
useWorkflowStore
();
const
executionRepository
=
useWorkflowExecutionStore
();
const
backoff
=
new
ExponentialBackoff
();
let
refreshTimeout
:
NodeJS
.
Timeout
|
undefined
=
undefined
;
let
intervalId
:
NodeJS
.
Time
r
|
undefined
=
undefined
;
let
pollingTimeout
:
NodeJS
.
Time
out
|
undefined
=
undefined
;
const
executionsState
=
reactive
<
{
loading
:
boolean
;
...
...
@@ -80,9 +82,17 @@ const deleteModalString = computed<string>(() => {
// Functions
// -----------------------------------------------------------------------------
function
updateExecutions
()
{
executionRepository
.
fetchExecutions
(()
=>
{
executionsState
.
loading
=
false
;
});
backoff
.
reset
();
clearTimeout
(
pollingTimeout
);
executionRepository
.
fetchExecutions
(()
=>
{
executionsState
.
loading
=
false
;
})
.
then
(()
=>
{
if
(
runningExecutions
.
value
.
length
>
0
)
{
refreshRunningWorkflowExecutionTimer
();
}
});
}
function
refreshExecutions
()
{
...
...
@@ -106,25 +116,37 @@ function cancelWorkflowExecution(executionId: string) {
executionRepository
.
cancelExecution
(
executionId
);
}
const
runningExecutions
=
computed
<
WorkflowExecutionOut
[]
>
(()
=>
executionRepository
.
executions
.
filter
((
execution
)
=>
workflowExecutionCancelable
(
execution
),
),
);
function
refreshRunningWorkflowExecution
()
{
Promise
.
all
(
executionRepository
.
executions
.
filter
((
execution
)
=>
workflowExecutionCancelable
(
execution
))
.
map
((
execution
)
=>
executionRepository
.
fetchExecution
(
execution
.
execution_id
),
),
runningExecutions
.
value
.
map
((
execution
)
=>
executionRepository
.
fetchExecution
(
execution
.
execution_id
),
),
);
}
async
function
refreshRunningWorkflowExecutionTimer
()
{
for
(
const
sleep
of
backoff
.
generator
())
{
await
new
Promise
((
resolve
)
=>
{
pollingTimeout
=
setTimeout
(
resolve
,
sleep
*
1000
);
});
refreshRunningWorkflowExecution
();
}
}
onMounted
(()
=>
{
updateExecutions
();
workflowRepository
.
fetchWorkflows
();
intervalId
=
setInterval
(
refreshRunningWorkflowExecution
,
5000
);
new
Tooltip
(
"
#refreshExecutionsButton
"
);
});
onUnmounted
(()
=>
{
clear
Interval
(
intervalId
);
clear
Timeout
(
pollingTimeout
);
});
</
script
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment