def add_template(self, template): """ @type template: Template """ eid = template.get_eid() xml = template.get_xml() id_ = template.get_id() all_templates = self._state.get("templates", {}) correct_eid_templates = all_templates.get(str(eid), []) if not exists(lambda t: t["id"] == id_ and t["xml"] == xml, correct_eid_templates): correct_eid_templates.append({ "eid": eid, "id": id_, "xml": xml }) all_templates[eid] = correct_eid_templates self._state["templates"] = all_templates correct_eid_template_instances = self._cached_templates.get(str(eid), []) if not exists(lambda t: t.get_id() == id_ and t.get_xml() == xml, correct_eid_template_instances): correct_eid_template_instances.append(template) self._cached_templates[str(eid)] = correct_eid_template_instances
def add_lost_record(self, offset, timestamp, record_num, substitutions): """ @type offset: int @type timestamp: datetime.datetime @param timestamp: timezone should be UTC @type record_num: int @type substitutions: list of (str, str) """ # need to fix up timestamps since they are not JSON serializable timestamp_types = set([17, 18]) if exists(lambda s: s[0] in timestamp_types, substitutions): new_subs = [] for sub in substitutions: if sub[0] in timestamp_types: new_subs.append((sub[0], sub[1].isoformat("T") + "Z")) else: new_subs.append(sub) substitutions = new_subs self._add_list_entry("lost_records", { "offset": offset, "timestamp": timestamp.isoformat("T") + "Z", "record_num": record_num, "substitutions": substitutions })
def add_template(self, template): """ @type template: Template """ eid = template.get_eid() xml = template.get_xml() id_ = template.get_id() all_templates = self._state.get("templates", {}) correct_eid_templates = all_templates.get(str(eid), []) if not exists(lambda t: t["id"] == id_ and t["xml"] == xml, correct_eid_templates): correct_eid_templates.append({"eid": eid, "id": id_, "xml": xml}) all_templates[eid] = correct_eid_templates self._state["templates"] = all_templates correct_eid_template_instances = self._cached_templates.get( str(eid), []) if not exists(lambda t: t.get_id() == id_ and t.get_xml() == xml, correct_eid_template_instances): correct_eid_template_instances.append(template) self._cached_templates[str(eid)] = correct_eid_template_instances