Commit 16990e1e authored by Jacob Schatz's avatar Jacob Schatz

Merge branch '1589-deploy-boards-2nd-iteration' into 'master'

Deploy board - second iteration

See merge request !1327
parents eff10bbb 33e2ecdb
/* eslint-disable no-new */ /* eslint-disable no-new, no-undef */
/* global Flash */ /* global Flash */
/** /**
* Renders a deploy board. * Renders a deploy board.
...@@ -67,47 +67,68 @@ export default { ...@@ -67,47 +67,68 @@ export default {
}, },
created() { created() {
this.isLoading = true; this.getDeployBoard();
},
updated() {
// While board is not complete we need to request new data from the server.
// Let's make sure we are not making any request at the moment
// and that we only make this request if the latest response was not 204.
if (!this.isLoading &&
!this.hasError &&
this.deployBoardData.completion &&
this.deployBoardData.completion < 100) {
// let's wait 1s and make the request again
setTimeout(() => {
this.getDeployBoard();
}, 3000);
}
},
methods: {
getDeployBoard() {
this.isLoading = true;
const maxNumberOfRequests = 3; const maxNumberOfRequests = 3;
// If the response is 204, we make 3 more requests. // If the response is 204, we make 3 more requests.
gl.utils.backOff((next, stop) => { gl.utils.backOff((next, stop) => {
this.service.getDeployBoard(this.endpoint) this.service.getDeployBoard(this.endpoint)
.then((resp) => { .then((resp) => {
if (resp.status === statusCodes.NO_CONTENT) { if (resp.status === statusCodes.NO_CONTENT) {
this.backOffRequestCounter = this.backOffRequestCounter += 1; this.backOffRequestCounter = this.backOffRequestCounter += 1;
if (this.backOffRequestCounter < maxNumberOfRequests) { if (this.backOffRequestCounter < maxNumberOfRequests) {
next(); next();
} else {
stop(resp);
}
} else { } else {
stop(resp); stop(resp);
} }
} else { })
stop(resp); .catch(stop);
} })
}) .then((resp) => {
.catch(stop); if (resp.status === statusCodes.NO_CONTENT) {
}) this.hasError = true;
.then((resp) => { return resp;
if (resp.status === statusCodes.NO_CONTENT) { }
this.hasError = true;
return resp; return resp.json();
} })
.then((response) => {
return resp.json(); this.store.storeDeployBoard(this.environmentID, response);
}) return response;
.then((response) => { })
this.store.storeDeployBoard(this.environmentID, response); .then(() => {
return response; this.isLoading = false;
}) })
.then(() => { .catch(() => {
this.isLoading = false; this.isLoading = false;
}) new Flash('An error occurred while fetching the deploy board.', 'alert');
.catch(() => { });
this.isLoading = false; },
new Flash('An error occurred while fetching the deploy board.', 'alert');
});
}, },
computed: { computed: {
......
...@@ -132,6 +132,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -132,6 +132,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
rollout_status = @environment.rollout_status rollout_status = @environment.rollout_status
Gitlab::PollingInterval.set_header(response, interval: 3000) unless rollout_status.try(:complete?)
if rollout_status.nil? if rollout_status.nil?
render body: nil, status: 204 # no result yet render body: nil, status: 204 # no result yet
else else
......
...@@ -266,6 +266,7 @@ describe Projects::EnvironmentsController do ...@@ -266,6 +266,7 @@ describe Projects::EnvironmentsController do
get :status, environment_params get :status, environment_params
expect(response.status).to eq(204) expect(response.status).to eq(204)
expect(response.headers['Poll-Interval']).to eq(3000)
end end
it 'returns the rollout status when present' do it 'returns the rollout status when present' do
......
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