def cancel_simulations(self, sim_list): """ Cancel all the simulations provided in id list. """ sim_batch = [] for simulation in sim_list: if simulation is None: continue if simulation.status not in [ SimulationState.Succeeded, SimulationState.Failed, SimulationState.Canceled, SimulationState.CommissionRequested ]: self.kill_simulation(simulation) # Add to the batch sim_batch.append({ 'sid': simulation.id, 'status': SimulationState.Canceled, 'message': None, 'pid': None }) # Batch update the statuses DataStore.batch_simulations_update(sim_batch)
def monitor(self): logger.debug('COMPS - Start Monitoring for experiment %s' % self.experiment.id) # Until done, update the status last_states = dict() for simulation in self.experiment.simulations: last_states[simulation.id] = simulation.status # Create the monitor monitor = CompsSimulationMonitor(self.experiment.exp_id, None, self.experiment.endpoint) # Until done, update the status while True: try: states, _ = monitor.query() if states == {}: # No states returned... Consider failed states = { sim_id: SimulationState.Failed for sim_id in last_states.keys() } except Exception as e: logger.error( 'Exception in the COMPS Monitor for experiment %s' % self.experiment.id) logger.error(e) # Only update the simulations that changed since last check # We are also including simulations that were not present (in case we add some later) DataStore.batch_simulations_update( list({ "sid": key, "status": states[key].name } for key in states if (key in last_states and last_states[key] != states[key] ) or key not in last_states)) # Store the last state last_states = states if CompsExperimentManager.status_finished(states): logger.debug( 'Stop monitoring for experiment %s because all simulations finished' % self.experiment.id) break time.sleep(self.MONITOR_SLEEP)