def serialize(self, entity): '''serialize any entity only need schema, message class not needed ''' #for now only handle miner, later add other entities schema = MinerSchema() return schema.dumps(entity).data
def serialize(self, entity): '''serialize any entity only need schema, message class not needed ''' if isinstance(entity, Miner): schema = MinerSchema() return schema.dumps(entity).data if isinstance(entity, Pool): schema = PoolSchema() return schema.dumps(entity).data
def deserializelistofstrings(self, the_list): '''deserialize list of strings into list of miners''' results = [] for item in the_list: miner = self.deserialize(MinerSchema(), self.safestring(item)) results.append(miner) return results
def getknownminerbyname(self, minername): '''todo: rename to bykey''' str_miner = self.__cache.getfromhashset(CacheKeys.knownminers, minername) if str_miner is None: return None return self.deserialize(MinerSchema(), self.safestring(str_miner))
def serialize(self, entity): '''serialize any entity only need schema, message class not needed ''' if isinstance(entity, Miner): return utils.serialize(entity, MinerSchema()) if isinstance(entity, Pool): return utils.serialize(entity, PoolSchema()) return None
def deserializelistofstrings(self, the_list): '''deserialize list of strings into list of miners''' results = [] for item in the_list: #thejson = json.loads(self.safestring(item)) #miner = Miner(**thejson) #TODO: the miner here is a Miner but the children are dicts miner = self.deserialize(MinerSchema(), self.safestring(item)) results.append(miner) return results
def updateknownminer(self, miner): '''update known miner in cache''' sminer = self.__cache.getfromhashset(CacheKeys.knownminers, miner.key()) memminer = self.deserialize(MinerSchema(), self.safestring(sminer)) if memminer is None: memminer = miner else: #merge new values memminer.updatefrom(miner) val = self.serialize(memminer) self.__cache.putinhashset(CacheKeys.knownminers, miner.key(), val)
def getminer(self, miner: Miner): '''strategies for getting miner from cache originally was key=miner.name but that was not good changed to key='miner.'+minerid ''' valu = self.trygetvaluefromcache('miner.{0}'.format(miner.key())) if valu is None: return None minerfromstore = self.deserialize(MinerSchema(), self.safestring(valu)) minerfromstore.store = 'mem' return minerfromstore