diff options
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/lib/utils/poll.js | 20 | ||||
-rw-r--r-- | app/assets/javascripts/pipelines/mixins/pipelines.js | 3 |
2 files changed, 18 insertions, 5 deletions
diff --git a/app/assets/javascripts/lib/utils/poll.js b/app/assets/javascripts/lib/utils/poll.js index 198711cf427..a900ff34bf5 100644 --- a/app/assets/javascripts/lib/utils/poll.js +++ b/app/assets/javascripts/lib/utils/poll.js @@ -63,6 +63,10 @@ export default class Poll { const headers = normalizeHeaders(response.headers); const pollInterval = parseInt(headers[this.intervalHeader], 10); if (pollInterval > 0 && successCodes.indexOf(response.status) !== -1 && this.canPoll) { + if (this.timeoutID) { + clearTimeout(this.timeoutID); + } + this.timeoutID = setTimeout(() => { this.makeRequest(); }, pollInterval); @@ -101,15 +105,25 @@ export default class Poll { } /** - * Restarts polling after it has been stoped + * Enables polling after it has been stopped */ - restart(options) { - // update data + enable(options) { if (options && options.data) { this.options.data = options.data; } this.canPoll = true; + + if (options && options.response) { + this.checkConditions(options.response); + } + } + + /** + * Restarts polling after it has been stopped and makes a request + */ + restart(options) { + this.enable(options); this.makeRequest(); } } diff --git a/app/assets/javascripts/pipelines/mixins/pipelines.js b/app/assets/javascripts/pipelines/mixins/pipelines.js index 32bfa47e5f2..74ca3071364 100644 --- a/app/assets/javascripts/pipelines/mixins/pipelines.js +++ b/app/assets/javascripts/pipelines/mixins/pipelines.js @@ -94,8 +94,7 @@ export default { this.isLoading = false; this.successCallback(response); - // restart polling - this.poll.restart({ data: this.requestData }); + this.poll.enable({ data: this.requestData, response }); }) .catch(() => { this.isLoading = false; |