def _clean_user_namespaced_items(self): users = get_all_mobile_users(self.session_key) timestamp_before = time_utils.get_current_timestamp() - self.clean_up_time LOGGER.debug('Deleting credentials older than last_update_time=%s, users=%s', timestamp_before, len(users)) for owner in users: credentials = KVStoreCollectionAccessObject(collection=SUBSCRIPTION_CREDENTIALS_COLLECTION_NAME, owner=owner, session_key=self.session_key) credentials.delete_expired_items(expired_time=timestamp_before, expiration_attribute_name=LAST_UPDATE_TIME)
def run(self): """ Goes through each alerts related collection and deletes items older than ttl_days """ LOGGER.info("Running alerts ttl utility") try: for kvstore_ttl_resource in self.ttl_resource_list: timestamp_attribute_name = kvstore_ttl_resource.time_attribute_name collection = kvstore_ttl_resource.collection_name ttl_num_seconds = day_to_seconds( kvstore_ttl_resource.ttl_num_days) collection_handler = KVStoreCollectionAccessObject( collection=kvstore_ttl_resource.collection_name, session_key=self.session_key, timestamp_attribute_name=timestamp_attribute_name) self.delete_invalid_entries(collection, collection_handler, timestamp_attribute_name) try: resp = collection_handler.delete_expired_items( expired_time=ttl_num_seconds) LOGGER.info( "Successfully performed TTL for collection=%s with response=%s" % (collection, str(resp))) except: LOGGER.exception( "Exception performing TTL for collection=%s" % collection) except: LOGGER.exception("Failure encountered during Alerts TTL ")