Commit 32bf2df9 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '2222-deploy-boards-polling' into 'master'

Uses new Polling technique on the Frontend - etag

Closes #2222

See merge request !1713
parents f420cde3 c40bd6e0
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
* Please refer to this [comment](https://gitlab.com/gitlab-org/gitlab-ee/issues/1589#note_23630610) * Please refer to this [comment](https://gitlab.com/gitlab-org/gitlab-ee/issues/1589#note_23630610)
* for more information * for more information
*/ */
import statusCodes from '~/lib/utils/http_status'; import Visibility from 'visibilityjs';
import '~/flash';
import '~/lib/utils/common_utils';
import deployBoardSvg from 'empty_states/icons/_deploy_board.svg'; import deployBoardSvg from 'empty_states/icons/_deploy_board.svg';
import instanceComponent from './deploy_board_instance_component.vue'; import instanceComponent from './deploy_board_instance_component.vue';
import Poll from '../../lib/utils/poll';
import '../../flash';
export default { export default {
...@@ -62,73 +62,45 @@ export default { ...@@ -62,73 +62,45 @@ export default {
return { return {
isLoading: false, isLoading: false,
hasError: false, hasError: false,
backOffRequestCounter: 0,
deployBoardSvg, deployBoardSvg,
}; };
}, },
created() { created() {
this.getDeployBoard(true); const poll = new Poll({
}, resource: this.service,
method: 'getDeployBoard',
updated() { data: this.endpoint,
// While board is not complete we need to request new data from the server. successCallback: this.successCallback,
// Let's make sure we are not making any request at the moment errorCallback: this.errorCallback,
// and that we only make this request if the latest response was not 204. });
if (!this.isLoading &&
!this.hasError && if (!Visibility.hidden()) {
this.deployBoardData.completion && this.isLoading = true;
this.deployBoardData.completion < 100) { poll.makeRequest();
// let's wait 1s and make the request again
setTimeout(() => {
this.getDeployBoard(false);
}, 3000);
} }
Visibility.change(() => {
if (!Visibility.hidden()) {
poll.restart();
} else {
poll.stop();
}
});
}, },
methods: { methods: {
getDeployBoard(showLoading) { successCallback(response) {
this.isLoading = showLoading; const data = response.json();
const maxNumberOfRequests = 3; this.store.storeDeployBoard(this.environmentID, data);
this.isLoading = false;
// If the response is 204, we make 3 more requests. },
gl.utils.backOff((next, stop) => {
this.service.getDeployBoard(this.endpoint) errorCallback() {
.then((resp) => { this.isLoading = false;
if (resp.status === statusCodes.NO_CONTENT) { // eslint-disable-next-line no-new
this.backOffRequestCounter = this.backOffRequestCounter += 1; new Flash('An error occurred while fetching the deploy board.');
if (this.backOffRequestCounter < maxNumberOfRequests) {
next();
} else {
stop(resp);
}
} else {
stop(resp);
}
})
.catch(stop);
})
.then((resp) => {
if (resp.status === statusCodes.NO_CONTENT) {
this.hasError = true;
return resp;
}
return resp.json();
})
.then((response) => {
this.store.storeDeployBoard(this.environmentID, response);
return response;
})
.then(() => {
this.isLoading = false;
})
.catch(() => {
this.isLoading = false;
new Flash('An error occurred while fetching the deploy board.', 'alert');
});
}, },
}, },
......
---
title: Uses etag polling for deployboards
merge_request: 1713
author:
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