Skip to content
Snippets Groups Projects
Select Git revision
  • 9448d917b9a0439d39e5cc3f3c580669bb6dd8a7
  • master default
  • rocky-linux-9
  • rocky-linux-8
  • debian11
  • lbtTimeoutFix
  • v1.1.2
  • v1.0.2
  • v1.0.1
  • v1.0.0
  • v1.0
  • beta1
12 results

ProtocolManager.h

Blame
  • nodesReloader.js 1.48 KiB
    /*
     * This file is part of vospace-ui
     * Copyright (C) 2021 Istituto Nazionale di Astrofisica
     * SPDX-License-Identifier: GPL-3.0-or-later
     */
    import store from './store.js'
    import client from 'api-client'
    
    let lastResultTime = null;
    let times = 0;
    
    function checkNodes() {
      let busyNodes = document.getElementsByClassName('node-busy').length > 0;
      let jobsInProgress = store.state.jobs.filter(j => j.phase === 'EXECUTING').length > 0;
      if (!busyNodes && !jobsInProgress) {
        // reset state
        lastResultTime = null;
        times = 0;
        return;
      }
      if (lastResultTime !== null) {
        // first 10 times check every second, then check every ten seconds
        let offset = times < 10 ? 1000 : 10000;
        let now = new Date().getTime();
        if (now - lastResultTime < offset) {
          return;
        }
      }
    
      if (!store.state.nodesLoading) {
        let path = store.state.path;
        store.commit('setNodesLoading', true);
        client.getNode(path, false)
          .then(res => {
            // check that path didn't change in meantime by user action
            if (path === store.state.path) {
              let resHasBusyNodes = res.html.includes('node-busy');
              if ((!busyNodes && resHasBusyNodes) || (busyNodes && !resHasBusyNodes)) {
                store.dispatch('setNodes', res);
              } else {
                times++;
                lastResultTime = new Date().getTime();
              }
            }
          })
          .finally(() => {
            store.commit('setNodesLoading', false);
          });
      }
    }
    
    export default {
      checkNodes
    }