def get(cluster_id, r=redis_client): """ gets the current status for the cluster :param cluster_id: id of the cluster :return: Stat or Status """ key = Stat.get_key(cluster_id) if r.exists(key): pack = r.get(key) try: return SignedPackage.loads(pack) except signing.BadSignature: return None return Status(cluster_id)
def get_all(r=redis_client): """ Gets status for all currently running clusters with the same prefix and secret key :return: list of type Stat """ stats = [] keys = r.keys(pattern='{}:*'.format(Conf.Q_STAT)) if keys: packs = r.mget(keys) for pack in packs: try: stats.append(SignedPackage.loads(pack)) except signing.BadSignature: continue return stats
def save(self): try: self.r.set(self.key, SignedPackage.dumps(self, True), 3) except Exception as e: logger.error(e)