Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1653d570
Commit
1653d570
authored
Nov 12, 2019
by
Dhiraj Bodicherla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cancelling previous backoff reqs
parent
c6974623
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
ee/app/assets/javascripts/custom_metrics/components/custom_metrics_form_fields.vue
.../custom_metrics/components/custom_metrics_form_fields.vue
+25
-6
No files found.
ee/app/assets/javascripts/custom_metrics/components/custom_metrics_form_fields.vue
View file @
1653d570
...
...
@@ -17,6 +17,8 @@ import { backOff } from '~/lib/utils/common_utils';
import
{
queryTypes
,
formDataValidator
}
from
'
../constants
'
;
const
MAX_REQUESTS
=
4
;
const
axiosCancelToken
=
axios
.
CancelToken
;
let
cancelTokenSource
;
function
backOffRequest
(
makeRequestCallback
)
{
let
requestsCount
=
0
;
...
...
@@ -34,7 +36,10 @@ function backOffRequest(makeRequestCallback) {
}
}
})
.
catch
(
stop
);
// If the request is cancelled by axios
// then consider it as noop so that its not
// caught by subsequent catches
.
catch
(
thrown
=>
(
axios
.
isCancel
(
thrown
)
?
undefined
:
stop
(
thrown
)));
});
}
...
...
@@ -114,11 +119,17 @@ export default {
}
},
methods
:
{
requestValidation
()
{
requestValidation
(
query
,
cancelToken
)
{
return
backOffRequest
(()
=>
axios
.
post
(
this
.
validateQueryPath
,
{
query
:
this
.
query
,
}),
axios
.
post
(
this
.
validateQueryPath
,
{
query
,
},
{
cancelToken
,
},
),
);
},
setFormState
(
isValid
,
inFlight
,
message
)
{
...
...
@@ -132,7 +143,15 @@ export default {
return
;
}
this
.
setFormState
(
null
,
true
,
''
);
this
.
requestValidation
()
// cancel previously dispatched backoff request
if
(
cancelTokenSource
)
{
cancelTokenSource
.
cancel
();
}
// Creating a new token for each request because
// if a single token is used it can cancel existing requests
// as well.
cancelTokenSource
=
axiosCancelToken
.
source
();
this
.
requestValidation
(
this
.
query
,
cancelTokenSource
.
token
)
.
then
(
res
=>
{
const
response
=
res
.
data
;
const
{
valid
,
error
}
=
response
.
query
;
...
...
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