15672: Update container runtime every 5 seconds
authorPeter Amstutz <peter.amstutz@curii.com>
Fri, 10 Jan 2020 20:25:17 +0000 (15:25 -0500)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 10 Jan 2020 20:25:17 +0000 (15:25 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

src/store/project-panel/project-panel-middleware-service.ts
src/views-components/data-explorer/renderers.tsx
src/websocket/websocket.ts

index 3a42d07eb897677d28889555c6f50fad7069a714..d4b2416ef6b05f163515d76b39619fa1ead13b23 100644 (file)
@@ -17,7 +17,7 @@ import { OrderBuilder, OrderDirection } from "~/services/api/order-builder";
 import { FilterBuilder, joinFilters } from "~/services/api/filter-builder";
 import { GroupContentsResource, GroupContentsResourcePrefix } from "~/services/groups-service/groups-service";
 import { updateFavorites } from "~/store/favorites/favorites-actions";
-import { PROJECT_PANEL_CURRENT_UUID, IS_PROJECT_PANEL_TRASHED, projectPanelActions } from '~/store/project-panel/project-panel-action';
+import { IS_PROJECT_PANEL_TRASHED, projectPanelActions, getProjectPanelCurrentUuid } from '~/store/project-panel/project-panel-action';
 import { Dispatch, MiddlewareAPI } from "redux";
 import { ProjectResource } from "~/models/project";
 import { updateResources } from "~/store/resources/resources-actions";
@@ -40,7 +40,7 @@ export class ProjectPanelMiddlewareService extends DataExplorerMiddlewareService
     async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
         const state = api.getState();
         const dataExplorer = getDataExplorer(state.dataExplorer, this.getId());
-        const projectUuid = getProperty<string>(PROJECT_PANEL_CURRENT_UUID)(state.properties);
+        const projectUuid = getProjectPanelCurrentUuid(state);
         const isProjectTrashed = getProperty<string>(IS_PROJECT_PANEL_TRASHED)(state.properties);
         if (!projectUuid) {
             api.dispatch(projectPanelCurrentUuidIsNotSet());
index 7680f33895e5675879df68a50eb9990898c550de..c118017d7a4e9eb91278d479b1fcdb22b81e76fe 100644 (file)
@@ -35,9 +35,9 @@ const renderName = (dispatch: Dispatch, item: { name: string; uuid: string, kind
         </Grid>
         <Grid item>
             <Typography color="primary" style={{ width: 'auto', cursor: 'pointer' }} onClick={() => dispatch<any>(navigateTo(item.uuid))}>
-                { item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
+                {item.kind === ResourceKind.PROJECT || item.kind === ResourceKind.COLLECTION
                     ? <IllegalNamingWarning name={item.name} />
-                    : null }
+                    : null}
                 {item.name}
             </Typography>
         </Grid>
@@ -461,8 +461,41 @@ export const renderRunTime = (time: number) =>
         {formatTime(time, true)}
     </Typography>;
 
-export const ContainerRunTime = connect(
-    (state: RootState, props: { uuid: string }) => {
-        const process = getProcess(props.uuid)(state.resources);
-        return { time: process ? getProcessRuntime(process) : 0 };
-    })((props: { time: number }) => renderRunTime(props.time));
\ No newline at end of file
+interface ContainerRunTimeProps {
+    process: Process;
+}
+
+interface ContainerRunTimeState {
+    runtime: number;
+}
+
+export const ContainerRunTime = connect((state: RootState, props: { uuid: string }) => {
+    return { process: getProcess(props.uuid)(state.resources) };
+})(class extends React.Component<ContainerRunTimeProps, ContainerRunTimeState> {
+    private timer: any;
+
+    constructor(props: ContainerRunTimeProps) {
+        super(props);
+        this.state = { runtime: this.getRuntime() };
+    }
+
+    getRuntime() {
+        return this.props.process ? getProcessRuntime(this.props.process) : 0;
+    }
+
+    updateRuntime() {
+        this.setState({ runtime: this.getRuntime() });
+    }
+
+    componentDidMount() {
+        this.timer = setInterval(this.updateRuntime.bind(this), 5000);
+    }
+
+    componentWillUnmount() {
+        clearInterval(this.timer);
+    }
+
+    render() {
+        return renderRunTime(this.state.runtime);
+    }
+});
index e367dba3e8f17fbf47fc420e3c7c419d48c6b966..3e740256c3f06f40cbc852b3ed8c4000962839b2 100644 (file)
@@ -15,6 +15,7 @@ import { addProcessLogsPanelItem } from '../store/process-logs-panel/process-log
 // import { FilterBuilder } from "~/services/api/filter-builder";
 import { subprocessPanelActions } from "~/store/subprocess-panel/subprocess-panel-actions";
 import { projectPanelActions } from "~/store/project-panel/project-panel-action";
+import { getProjectPanelCurrentUuid } from '~/store/project-panel/project-panel-action';
 
 export const initWebSocket = (config: Config, authService: AuthService, store: RootStore) => {
     if (config.websocketUrl) {
@@ -33,9 +34,12 @@ const messageListener = (store: RootStore) => (message: ResourceEventMessage) =>
                 if (store.getState().processPanel.containerRequestUuid === message.objectUuid) {
                     store.dispatch(loadProcess(message.objectUuid));
                 }
+            // fall through, this will happen for container requests as well.
             case ResourceKind.CONTAINER:
                 store.dispatch(subprocessPanelActions.REQUEST_ITEMS());
-                store.dispatch(projectPanelActions.REQUEST_ITEMS());
+                if (message.objectOwnerUuid === getProjectPanelCurrentUuid(store.getState())) {
+                    store.dispatch(projectPanelActions.REQUEST_ITEMS());
+                }
                 return;
             default:
                 return;