def setup_class(cls): os.environ['ALLOW_DAT'] = '1' super(TestDatShare, cls).setup_class(storage_worker=True) cls.manager = CLIUserManager() cls.set_uuids('Collection', count(int(cls.COLL_ID) - 1)) cls.dat_info = {'datKey': get_new_id(size=20), 'discoveryKey': get_new_id(size=20) }
def get_new_id(cls, max_len=None): """Get new unique ID. :param max_len: maximum length :type: int or None :returns: unique ID :rtype: str """ return get_new_id(max_len)
def commit_all(self, commit_id=None): # see if pending commits have been finished if commit_id: commit_key = self.CLOSE_WAIT_KEY.format(coll=self.my_id, id=commit_id) open_rec_ids = self.redis.smembers(commit_key) still_waiting = False for rec_id in open_rec_ids: recording = self.get_recording(rec_id) if recording.is_fully_committed(): continue still_waiting = True if not still_waiting: self.redis.delete(commit_key) return None return commit_id open_recs = [] for recording in self.get_recordings(): if recording.is_open(): recording.set_closed() recording.commit_to_storage() elif recording.is_fully_committed(): continue open_recs.append(recording) if not open_recs: return None commit_id = get_new_id(5) commit_key = self.CLOSE_WAIT_KEY.format(coll=self.my_id, id=commit_id) open_keys = [recording.my_id for recording in open_recs] self.redis.sadd(commit_key, *open_keys) self.redis.expire(commit_key, 200) return commit_id
def get_new_id(cls, max_len=None): return get_new_id(max_len)
def get_new_id_o(self, max_len=None): try: id_gen = cls.ids_map.get(self.__class__.__name__) return str(next(id_gen)) except: return get_new_id(max_len)