def _process_event(self, id_, event): """Processes the given event, updating the instance data structures accordingly.""" datetime_ = event['datetime'] if event['status'] is not None: status = event['status'] prevstatus = self.status[id_]['status'] # Avoid overwriting a status with a less important one. if status == CrabStatus.CLEARED: self.status[id_]['status'] = status elif CrabStatus.is_trivial(status): if prevstatus is None or CrabStatus.is_ok(prevstatus): self.status[id_]['status'] = status elif CrabStatus.is_warning(status): if prevstatus is None or not CrabStatus.is_error(prevstatus): self.status[id_]['status'] = status # Always set success / failure status (the remaining options). else: self.status[id_]['status'] = status if not CrabStatus.is_trivial(status): history = self.status[id_]['history'] if len(history) >= HISTORY_COUNT: del history[0] history.append(status) # Handle ALREADYRUNNING as a 'start' type event, so that # the MISSED alarm is not raised and the timeout period # is extended. if (event['type'] == CrabEvent.START or event['status'] == CrabStatus.ALREADYRUNNING): self.status[id_]['running'] = True if not self.passive: self.last_start[id_] = datetime_ self.timeout[id_] = datetime_ + self.config[id_]['timeout'] if id_ in self.late_timeout: del self.late_timeout[id_] if id_ in self.miss_timeout: del self.miss_timeout[id_] elif (event['type'] == CrabEvent.FINISH or event['status'] == CrabStatus.TIMEOUT): self.status[id_]['running'] = False if not self.passive: if id_ in self.timeout: del self.timeout[id_]
def _process_event(self, id_, event): """Processes the given event, updating the instance data structures accordingly.""" datetime_ = event['datetime'] if event['status'] is not None: status = event['status'] prevstatus = self.status[id_]['status'] # Avoid overwriting a status with a less important one. if status == CrabStatus.CLEARED: self.status[id_]['status'] = status elif CrabStatus.is_trivial(status): if prevstatus is None or CrabStatus.is_ok(prevstatus): self.status[id_]['status'] = status elif CrabStatus.is_warning(status): if prevstatus is None or not CrabStatus.is_error(prevstatus): self.status[id_]['status'] = status # Always set success / failure status (the remaining options). else: self.status[id_]['status'] = status if not CrabStatus.is_trivial(status): history = self.status[id_]['history'] if len(history) >= HISTORY_COUNT: del history[0] history.append(status) # Handle ALREADYRUNNING as a 'start' type event, so that # the MISSED alarm is not raised and the timeout period # is extended. if (event['type'] == CrabEvent.START or event['status'] == CrabStatus.ALREADYRUNNING): self.status[id_]['running'] = True if not self.passive: self.last_start[id_] = datetime_ self.timeout[id_] = datetime_ + self.config[id_]['timeout'] if id_ in self.late_timeout: del self.late_timeout[id_] if id_ in self.miss_timeout: del self.miss_timeout[id_] elif (event['type'] == CrabEvent.FINISH or event['status'] == CrabStatus.TIMEOUT): self.status[id_]['running'] = False if not self.passive: if id_ in self.timeout: del self.timeout[id_]
def __call__(self, events, skip_ok=False, skip_warning=False, skip_error=False, skip_trivial=True, skip_start=False, squash_start=False): """Performs filtering, and returns the altered event list.""" output = [] squash = set() self.errors = 0 self.warnings = 0 for (i, e) in enumerate(events): if i in squash: continue e = e.copy() if e['type'] == CrabEvent.START: if skip_start: continue else: if (skip_trivial and CrabStatus.is_trivial(e['status']) or skip_ok and CrabStatus.is_ok(e['status']) or skip_warning and CrabStatus.is_warning(e['status']) or skip_error and CrabStatus.is_error(e['status'])): continue if CrabStatus.is_error(e['status']): self.errors += 1 if CrabStatus.is_warning(e['status']): self.warnings += 1 if squash_start and e['type'] == CrabEvent.FINISH: start = _find_previous_start(events, i) if start is not None: squash.add(start) delta = ( self.store.parse_datetime(e['datetime']) - self.store.parse_datetime(events[start]['datetime'])) e['duration'] = str(delta) e['datetime'] = self.in_timezone(e['datetime']) output.append(e) return output
def __call__(self, events, skip_ok=False, skip_warning=False, skip_error=False, skip_trivial=True, skip_start=False, squash_start=False): """Performs filtering, and returns the altered event list.""" output = [] squash = set() self.errors = 0 self.warnings = 0 for (i, e) in enumerate(events): if i in squash: continue e = e.copy() if e['type'] == CrabEvent.START: if skip_start: continue else: if (skip_trivial and CrabStatus.is_trivial(e['status']) or skip_ok and CrabStatus.is_ok(e['status']) or skip_warning and CrabStatus.is_warning(e['status']) or skip_error and CrabStatus.is_error(e['status'])): continue if CrabStatus.is_error(e['status']): self.errors += 1 if CrabStatus.is_warning(e['status']): self.warnings += 1 if squash_start and e['type'] == CrabEvent.FINISH: start = _find_previous_start(events, i) if start is not None: squash.add(start) delta = (self.store.parse_datetime(e['datetime']) - self.store.parse_datetime(events[start]['datetime'])) e['duration'] = str(delta) e['datetime'] = self.in_timezone(e['datetime']) output.append(e) return output
def _find_previous_start(events, i): """Looks in the event list, past position i, for the previous start. Skips over alarms and other trivial events.""" i += 1 while (i < len(events)): e = events[i] if e['type'] == CrabEvent.START: return i elif (e['type'] != CrabEvent.ALARM and not CrabStatus.is_trivial(e['status'])): return None i += 1 return None
def _find_previous_start(events, i): """Looks in the event list, past position i, for the previous start. Skips over alarms and other trivial events.""" i += 1 while (i < len(events)): e = events[i] if e['type'] == CrabEvent.START: return i elif (e['type'] != CrabEvent.ALARM and not CrabStatus.is_trivial(e['status'])): return None i += 1 return None