Skip to content
Snippets Groups Projects
Select Git revision
  • c169b072261f99b0e56bfa43db711ea06849d6f7
  • main default protected
  • s3_dev
  • s2_dev
  • nuovo_branch2
  • nuovo_branch
  • dario.delmoro-main-patch-65693
  • dario.delmoro-main-patch-95280
  • edit1
9 results

aspis.rst

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
    }