def sleep_until_state(j, timeout=None, state='completed', break_states=None, sleep_period=1, verbose=False): ''' Wait until the job reaches the specified state Returns: True: if the state has been reached in the given timeout period False: timeout occured or a break state has been reached If break_states is specified, the call terminates when job enters in one of these state, returning False ''' from Ganga.GPIDev.Base.Proxy import stripProxy j = stripProxy(j) if j.master is not None: j = j.master if timeout is None: timeout = config['timeout'] from time import sleep from Ganga.Core import monitoring_component from Ganga.Core.GangaRepository import getRegistryProxy jobs = getRegistryProxy('jobs') current_status = None while j.status != state and timeout > 0: if not monitoring_component.isEnabled(): monitoring_component.runMonitoring(jobs=jobs.select(j.id, j.id), _loadCredentials=False) else: monitoring_component.alive = True monitoring_component.enabled = True monitoring_component.steps = -1 monitoring_component.__updateTimeStamp = 0 monitoring_component.__sleepCounter = -0.5 if verbose and j.status != current_status: logger.info("Job %s: status = %s" % (str(j.id), str(j.status))) if current_status is None: current_status = j.status if type(break_states) == type([]) and j.status in break_states: logger.info("Job finished with status: %s" % j.status) return False sleep(sleep_period) timeout -= sleep_period logger.debug("Status: %s" % j.status) logger.info("Job finished with status: %s" % j.status) logger.info("Timeout: %s" % str(timeout)) try: j._getRegistry().updateLocksNow() except: pass return j.status == state
def sleep_until_state(j, timeout=None, state='completed', break_states=None, sleep_period=1, verbose=False): ''' Wait until the job reaches the specified state Returns: True: if the state has been reached in the given timeout period False: timeout occured or a break state has been reached If break_states is specified, the call terminates when job enters in one of these state, returning False ''' from Ganga.GPIDev.Base.Proxy import stripProxy j = stripProxy(j) if j.master is not None: j = j.master if timeout is None: timeout = config['timeout'] from time import sleep from Ganga.Core import monitoring_component from Ganga.Core.GangaRepository import getRegistryProxy jobs = getRegistryProxy('jobs') current_status = None while j.status != state and timeout > 0: if not monitoring_component.isEnabled(): monitoring_component.runMonitoring(jobs=jobs.select(j.id,j.id)) else: monitoring_component.alive = True monitoring_component.enabled = True monitoring_component.steps = -1 monitoring_component.__updateTimeStamp = 0 monitoring_component.__sleepCounter = -0.5 if verbose and j.status != current_status: logger.info("Job %s: status = %s" % (str(j.id), str(j.status))) if current_status is None: current_status = j.status if type(break_states) == type([]) and j.status in break_states: logger.info("Job finished with status: %s" % j.status ) return False sleep(sleep_period) timeout -= sleep_period logger.debug("Status: %s" % j.status) logger.info("Job finished with status: %s" % j.status ) logger.info("Timeout: %s" % str(timeout)) try: j._getRegistry().updateLocksNow() except: pass return j.status == state
def sleep_until_state(j, timeout=None, state='completed', break_states=None, sleep_period=1, verbose=False): ''' Wait until the job reaches the specified state Returns: True: if the state has been reached in the given timeout period False: timeout occured or a break state has been reached If break_states is specified, the call terminates when job enters in one of these state, returning False ''' if timeout is None: timeout = config['timeout'] from time import sleep from Ganga.Core import monitoring_component from Ganga.GPI import jobs current_status = None while j.status != state and timeout > 0: if not monitoring_component.isEnabled(): monitoring_component.runMonitoring( jobs[j.id] ) else: monitoring_component.alive = True monitoring_component.enabled = True monitoring_component.steps = -1 monitoring_component.__updateTimeStamp = 0 monitoring_component.__sleepCounter = -0.5 if verbose and j.status != current_status: logger.info(j.id, j.status) if current_status is None: current_status = j.status if type(break_states) == type([]) and j.status in break_states: logger.info("Job finished with status: %s" % j.status ) return False sleep(sleep_period) timeout -= sleep_period logger.debug("Status: %s" % j.status) logger.info("Job finished with status: %s" % j.status ) logger.info("Timeout: %s" % str(timeout)) return j.status == state