فهرست منبع

Merge pull request #159 from smiclea/fix-polling

Fix replicas page polling issue in rare situation
Dorin Paslaru 8 سال پیش
والد
کامیت
4a89b40fe4
2فایلهای تغییر یافته به همراه39 افزوده شده و 2 حذف شده
  1. 35 1
      src/components/pages/MigrationsPage/index.jsx
  2. 4 1
      src/components/pages/ReplicasPage/index.jsx

+ 35 - 1
src/components/pages/MigrationsPage/index.jsx

@@ -36,6 +36,7 @@ import MigrationStore from '../../../stores/MigrationStore'
 import EndpointStore from '../../../stores/EndpointStore'
 import Wait from '../../../utils/Wait'
 import NotificationStore from '../../../stores/NotificationStore'
+import { requestPollTimeout } from '../../../config'
 
 const Wrapper = styled.div``
 
@@ -48,9 +49,13 @@ type State = {
   showDeleteMigrationConfirmation: boolean,
   showCancelMigrationConfirmation: boolean,
   confirmationItems: ?MainItem[],
+  modalIsOpen: boolean,
 }
 @observer
 class MigrationsPage extends React.Component<{}, State> {
+  pollTimeout: TimeoutID
+  stopPolling: boolean
+
   constructor() {
     super()
 
@@ -58,6 +63,7 @@ class MigrationsPage extends React.Component<{}, State> {
       showDeleteMigrationConfirmation: false,
       showCancelMigrationConfirmation: false,
       confirmationItems: null,
+      modalIsOpen: false,
     }
   }
 
@@ -66,7 +72,14 @@ class MigrationsPage extends React.Component<{}, State> {
 
     ProjectStore.getProjects()
     EndpointStore.getEndpoints()
-    MigrationStore.getMigrations()
+
+    this.stopPolling = false
+    this.pollData()
+  }
+
+  componentWillUnmount() {
+    clearTimeout(this.pollTimeout)
+    this.stopPolling = true
   }
 
   getEndpoint(endpointId: string) {
@@ -160,6 +173,16 @@ class MigrationsPage extends React.Component<{}, State> {
     window.location.href = '/#/wizard/migration'
   }
 
+  handleModalOpen() {
+    this.setState({ modalIsOpen: true })
+  }
+
+  handleModalClose() {
+    this.setState({ modalIsOpen: false }, () => {
+      this.pollData()
+    })
+  }
+
   searchText(item: MainItem, text?: string) {
     let result = false
     if (item.instances[0].toLowerCase().indexOf(text || '') > -1) {
@@ -187,6 +210,15 @@ class MigrationsPage extends React.Component<{}, State> {
     return true
   }
 
+  pollData() {
+    if (this.state.modalIsOpen || this.stopPolling) {
+      return
+    }
+    MigrationStore.getMigrations().then(() => {
+      this.pollTimeout = setTimeout(() => { this.pollData() }, requestPollTimeout)
+    })
+  }
+
   render() {
     const renderAlert = () => {
       const isDelete = this.state.showDeleteMigrationConfirmation
@@ -242,6 +274,8 @@ class MigrationsPage extends React.Component<{}, State> {
             <PageHeader
               title="Coriolis Migrations"
               onProjectChange={project => { this.handleProjectChange(project) }}
+              onModalOpen={() => { this.handleModalOpen() }}
+              onModalClose={() => { this.handleModalClose() }}
             />
           }
         />

+ 4 - 1
src/components/pages/ReplicasPage/index.jsx

@@ -53,6 +53,7 @@ type State = {
 @observer
 class ReplicasPage extends React.Component<{}, State> {
   pollTimeout: TimeoutID
+  stopPolling: boolean
 
   constructor() {
     super()
@@ -70,11 +71,13 @@ class ReplicasPage extends React.Component<{}, State> {
     ProjectStore.getProjects()
     EndpointStore.getEndpoints()
 
+    this.stopPolling = false
     this.pollData()
   }
 
   componentWillUnmount() {
     clearTimeout(this.pollTimeout)
+    this.stopPolling = true
   }
 
   getEndpoint(endpointId: string) {
@@ -169,7 +172,7 @@ class ReplicasPage extends React.Component<{}, State> {
   }
 
   pollData() {
-    if (this.state.modalIsOpen) {
+    if (this.state.modalIsOpen || this.stopPolling) {
       return
     }
     ReplicaStore.getReplicas().then(() => {