Beispiel #1
0
 def add_log(self, gid, message):
     # log to log file
     self.logger.error('User Log [{0}]: {1}'.format(gid, message))
     # log to gid's log if key does not exist
     if self.rc.zscore(S1.gid_log_key(gid), message):
         return
     # add new record
     self.rc.zadd(S1.gid_log_key(gid), message, time.time())
     # trim log to latest 99 messages
     self.rc.zremrangebyrank(S1.gid_log_key(gid), 0, -100)
Beispiel #2
0
    def get_log(self, gid):
        # get child account logs too
        children = set(self.get_destination_users(gid, 'children'))
        children.add(gid)
        log = {
            k: self.rc.zrange(S1.gid_log_key(k), 0, -1, withscores=True)
            for k in children
        }

        return log
Beispiel #3
0
    def forget_source(self, master_gid, gid):
        """
        Removes source gid, unlinks all bindings associated with the source
        @param master_gid: master gid
        @param gid: source gid
        @return:
        """
        self.logger.info('Removing source [{0}:{1}]...'.format(
            master_gid, gid))
        destinations = self.get_destinations(gid)
        for destination in destinations:
            users = self.get_destination_users(gid, destination)
            for user in users:
                # source gid can be bound to destination that does not belong to this master gid
                # forget_destination will only remove bindings that belong to this master gid
                DataApi.forget_destination(self, self.logger, gid, destination,
                                           user)

        # remove the gid from the list of child accounts
        self.remove_linked_account(master_gid, gid)

        # clear gid data if no destinations left
        destinations = self.get_destinations(gid)
        if not destinations:
            self.logger.info(
                'Source [{0}:{1}] is orphaned, cleaning...'.format(
                    master_gid, gid))
            # remove user keys
            self.rc.delete(S1.gid_key(gid))
            self.rc.delete(S1.gid_log_key(gid))
            self.rc.delete(S1.links_key(gid))
            self.rc.delete(S1.cache_key(gid))
            self.del_destination_param(gid, 'cache', '',
                                       S1.cache_shorten_urls())
            # clear chache and remove gid from poller list
            self.remove_from_poller(gid)
            # remove tnc
            self.rc.hdel(S1.TERMS_OK_KEY, gid)
Beispiel #4
0
 def del_log(self, gid):
     self.rc.delete(S1.gid_log_key(gid))