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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
49948c1f
Commit
49948c1f
authored
Jul 30, 2018
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes poll.js to keep polling on any 2xx http status code
parent
3d2dad44
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
28 deletions
+61
-28
app/assets/javascripts/lib/utils/http_status.js
app/assets/javascripts/lib/utils/http_status.js
+25
-2
app/assets/javascripts/lib/utils/poll.js
app/assets/javascripts/lib/utils/poll.js
+2
-2
changelogs/unreleased/49747-update-poll-2xx.yml
changelogs/unreleased/49747-update-poll-2xx.yml
+5
-0
doc/development/fe_guide/performance.md
doc/development/fe_guide/performance.md
+7
-7
spec/javascripts/lib/utils/poll_spec.js
spec/javascripts/lib/utils/poll_spec.js
+22
-17
No files found.
app/assets/javascripts/lib/utils/http_status.js
View file @
49948c1f
...
...
@@ -2,11 +2,34 @@
* exports HTTP status codes
*/
export
default
{
const
httpStatusCodes
=
{
ABORTED
:
0
,
NO_CONTENT
:
204
,
OK
:
200
,
CREATED
:
201
,
ACCEPTED
:
202
,
NON_AUTHORITATIVE_INFORMATION
:
203
,
NO_CONTENT
:
204
,
RESET_CONTENT
:
205
,
PARTIAL_CONTENT
:
206
,
MULTI_STATUS
:
207
,
ALREADY_REPORTED
:
208
,
IM_USED
:
226
,
MULTIPLE_CHOICES
:
300
,
BAD_REQUEST
:
400
,
NOT_FOUND
:
404
,
};
export
const
successCodes
=
[
httpStatusCodes
.
OK
,
httpStatusCodes
.
CREATED
,
httpStatusCodes
.
ACCEPTED
,
httpStatusCodes
.
NON_AUTHORITATIVE_INFORMATION
,
httpStatusCodes
.
NO_CONTENT
,
httpStatusCodes
.
RESET_CONTENT
,
httpStatusCodes
.
PARTIAL_CONTENT
,
httpStatusCodes
.
MULTI_STATUS
,
httpStatusCodes
.
ALREADY_REPORTED
,
httpStatusCodes
.
IM_USED
,
];
export
default
httpStatusCodes
;
app/assets/javascripts/lib/utils/poll.js
View file @
49948c1f
import
httpStatusCodes
from
'
./http_status
'
;
import
httpStatusCodes
,
{
successCodes
}
from
'
./http_status
'
;
import
{
normalizeHeaders
}
from
'
./common_utils
'
;
/**
...
...
@@ -62,7 +62,7 @@ export default class Poll {
checkConditions
(
response
)
{
const
headers
=
normalizeHeaders
(
response
.
headers
);
const
pollInterval
=
parseInt
(
headers
[
this
.
intervalHeader
],
10
);
if
(
pollInterval
>
0
&&
response
.
status
===
httpStatusCodes
.
OK
&&
this
.
canPoll
)
{
if
(
pollInterval
>
0
&&
successCodes
.
indexOf
(
response
.
status
)
!==
-
1
&&
this
.
canPoll
)
{
clearTimeout
(
this
.
timeoutID
);
this
.
timeoutID
=
setTimeout
(()
=>
{
this
.
makeRequest
();
...
...
changelogs/unreleased/49747-update-poll-2xx.yml
0 → 100644
View file @
49948c1f
---
title
:
Changes poll.js to keep polling on any 2xx http status code
merge_request
:
20904
author
:
type
:
other
doc/development/fe_guide/performance.md
View file @
49948c1f
...
...
@@ -15,7 +15,7 @@ Use the following rules when creating realtime solutions.
Use that as your polling interval. This way it is
[
easy for system administrators to change the
polling rate
](
../../administration/polling.md
)
.
A
`Poll-Interval: -1`
means you should disable polling, and this must be implemented.
1.
A response with HTTP status
`4XX`
or
`5XX`
should disable polling as well.
1.
A response with HTTP status
different from 2XX
should disable polling as well.
1.
Use a common library for polling.
1.
Poll on active tabs only. Please use
[
Visibility
](
https://github.com/ai/visibilityjs
)
.
1.
Use regular polling intervals, do not use backoff polling, or jitter, as the interval will be
...
...
spec/javascripts/lib/utils/poll_spec.js
View file @
49948c1f
import
Poll
from
'
~/lib/utils/poll
'
;
import
{
successCodes
}
from
'
~/lib/utils/http_status
'
;
const
waitForAllCallsToFinish
=
(
service
,
waitForCount
,
successCallback
)
=>
{
const
timer
=
()
=>
{
...
...
@@ -91,8 +92,10 @@ describe('Poll', () => {
}).
catch
(
done
.
fail
);
});
it
(
'
starts polling when http status is 200 and interval header is provided
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
describe
(
'
for 2xx status code
'
,
()
=>
{
successCodes
.
forEach
(
httpCode
=>
{
it
(
`starts polling when http status is
${
httpCode
}
and interval header is provided`
,
(
done
)
=>
{
mockServiceCall
(
service
,
{
status
:
httpCode
,
headers
:
{
'
poll-interval
'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
@@ -115,6 +118,8 @@ describe('Poll', () => {
done
();
});
});
});
});
describe
(
'
stop
'
,
()
=>
{
it
(
'
stops polling when method is called
'
,
(
done
)
=>
{
...
...
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