Browse Source

Poll replica status if current status is running CORWEB-23

Reset the open state of the running execution's rows to keep only the running tasks open.
Sergiu Miclea 8 years ago
parent
commit
2edf84888b

+ 22 - 0
src/components/ReplicaView/ReplicaView.js

@@ -27,6 +27,7 @@ import LoadingIcon from '../LoadingIcon';
 import TextTruncate from 'react-text-truncate';
 import Location from '../../core/Location';
 import ConfirmationDialog from '../ConfirmationDialog'
+import { tasksPollTimeout } from '../../config'
 
 class ReplicaView extends Reflux.Component {
 
@@ -62,14 +63,35 @@ class ReplicaView extends Reflux.Component {
 
   componentDidMount() {
     this.context.onSetTitle(this.state.title);
+    this.pollReplicaExecution()
+  }
+
+  componentWillUnmount() {
+    super.componentWillUnmount.call(this)
+    clearInterval(this.interval)
+  }
+
+  pollReplicaExecution() {
+    clearInterval(this.interval)
+    this.interval = setInterval(this.pollReplicaExecution.bind(this), tasksPollTimeout)
+
+    MigrationActions.getReplicaExecutions(this.state.replicas.find(replica => replica.id == this.props.replicaId),
+      () => {
+        let execs = this.state.replicas.find(r => r.id == this.props.replicaId).executions
+        if (execs && execs.length && execs[execs.length - 1].status !== 'RUNNING') {
+          clearInterval(this.interval)
+        }
+      })
   }
 
   executeReplica() {
     this.setState({ isBeingExecuted: true })
     let item = this.state.replicas.filter(replica => replica.id == this.props.replicaId)[0]
     MigrationActions.executeReplica(item, () => {
+      this.pollReplicaExecution()
       this.setState({ isBeingExecuted: false })
     }, () => {
+      this.pollReplicaExecution()
       this.setState({ isBeingExecuted: false })
     })
   }

+ 5 - 2
src/components/Table/Table.js

@@ -26,7 +26,8 @@ class Table extends Component {
     headerItems: [],
     listItems: [],
     parentId: null,
-    show: true
+    show: true,
+    resetOpenState: false
   }
 
   static propTypes = {
@@ -34,7 +35,8 @@ class Table extends Component {
     listItems: PropTypes.array,
     customClassName: PropTypes.string,
     show: PropTypes.bool,
-    parentId: PropTypes.string
+    parentId: PropTypes.string,
+    resetOpenState: PropTypes.bool
   }
 
   constructor(props) {
@@ -52,6 +54,7 @@ class Table extends Component {
       // i.e. don't close the collapser if new props arrive
       let isSameParent = this.state.parentId === null || newProps.parentId === this.state.parentId
       let prevOpenState = isSameParent && this.state.openState[i]
+      prevOpenState = newProps.resetOpenState ? false : prevOpenState
       openState.push(newProps.listItems[i].openState || prevOpenState)
     }
     this.setState({ openState: openState, parentId: newProps.parentId })

+ 1 - 0
src/components/Tasks/Tasks.js

@@ -177,6 +177,7 @@ class Tasks extends Component {
           (<div className={s.container}>
             <Table
               headerItems={this.headers}
+              resetOpenState={this.state.execution && this.state.execution.status === 'RUNNING'}
               parentId={this.state.execution && this.state.execution.id}
               listItems={this.state ? this.state.listItems : null}
               customClassName={s.table}