Commit 156171ca authored by Payton Burdette's avatar Payton Burdette Committed by Olena Horal-Koretska

Fix polling bug

Stop polling once pipeline
has a finished status.
parent 7145daf0
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
name: 'PipelineHeaderSection', name: 'PipelineHeaderSection',
pipelineCancel: 'pipelineCancel', pipelineCancel: 'pipelineCancel',
pipelineRetry: 'pipelineRetry', pipelineRetry: 'pipelineRetry',
finishedStatuses: ['FAILED', 'SUCCESS', 'CANCELED'],
components: { components: {
ciHeader, ciHeader,
GlAlert, GlAlert,
...@@ -95,6 +96,9 @@ export default { ...@@ -95,6 +96,9 @@ export default {
status() { status() {
return this.pipeline?.status; return this.pipeline?.status;
}, },
isFinished() {
return this.$options.finishedStatuses.includes(this.status);
},
shouldRenderContent() { shouldRenderContent() {
return !this.isLoadingInitialQuery && this.hasPipelineData; return !this.isLoadingInitialQuery && this.hasPipelineData;
}, },
...@@ -123,6 +127,13 @@ export default { ...@@ -123,6 +127,13 @@ export default {
} }
}, },
}, },
watch: {
isFinished(finished) {
if (finished) {
this.$apollo.queries.pipeline.stopPolling();
}
},
},
methods: { methods: {
reportFailure(errorType) { reportFailure(errorType) {
this.failureType = errorType; this.failureType = errorType;
...@@ -141,7 +152,10 @@ export default { ...@@ -141,7 +152,10 @@ export default {
if (errors.length > 0) { if (errors.length > 0) {
this.reportFailure(POST_FAILURE); this.reportFailure(POST_FAILURE);
} else { } else {
this.$apollo.queries.pipeline.refetch(); await this.$apollo.queries.pipeline.refetch();
if (!this.isFinished) {
this.$apollo.queries.pipeline.startPolling(POLL_INTERVAL);
}
} }
} catch { } catch {
this.reportFailure(POST_FAILURE); this.reportFailure(POST_FAILURE);
......
...@@ -97,6 +97,24 @@ describe('Pipeline details header', () => { ...@@ -97,6 +97,24 @@ describe('Pipeline details header', () => {
); );
}); });
describe('polling', () => {
it('is stopped when pipeline is finished', async () => {
wrapper = createComponent({ ...mockRunningPipelineHeader });
await wrapper.setData({
pipeline: { ...mockCancelledPipelineHeader },
});
expect(wrapper.vm.$apollo.queries.pipeline.stopPolling).toHaveBeenCalled();
});
it('is not stopped when pipeline is not finished', () => {
wrapper = createComponent();
expect(wrapper.vm.$apollo.queries.pipeline.stopPolling).not.toHaveBeenCalled();
});
});
describe('actions', () => { describe('actions', () => {
describe('Retry action', () => { describe('Retry action', () => {
beforeEach(() => { beforeEach(() => {
......
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