def connect_redis(self, host, port, db):
        config = {'host': host, 'port': port, 'db': db}

        try:
            self.redis_conf = redis.StrictRedis(**config)
            lpl.info(
                'Current redis configuration => Host : {h}, Port : {p}, DB : {d}'
                .format(h=host, p=port, d=db))

        except Exception as e:
            lpl.error('Cannot configure redis')
            lpl.error(e)
            raise e
    def main(self):
        args = sys.argv[1:]
        cmd_name = args[0]
        cmd_param = args[1:]

        to_file = '{}/avdrunner.log'.format(
            AVD_LOGPATH) if AVD_LOGPATH else None

        lpl.init_logger('AVDRunner', to_stream=False, to_file=to_file)

        cmd = local[cmd_name]
        lpl.info('Running {} with params {}'.format(cmd_name, cmd_param))
        exit_code = cmd[cmd_param] & RETCODE(FG=True)
        lpl.info('{} completed. exit_code: {}'.format(cmd_name, exit_code))
        if exit_code != 0:
            lpl.error('Command {} with params {} FAILED'.format(
                cmd_name, cmd_param))
    def publish_key(self, list_key, channel_key, docs_to_publish_count,
                    show_progress_bar):
        if (docs_to_publish_count == 0):
            docs_to_publish = []
        else:
            docs_to_publish = self.redis_conf.lrange(
                list_key,
                abs(docs_to_publish_count) * -1, -1)

        lpl.debug(
            'Documents to publish from key {k} to channel {c}: {d}'.format(
                k=list_key, c=channel_key, d=docs_to_publish))
        lpl.info('Documents to publish from key {k} to channel {c}: {d},'
                 ' Show progress bar :  {s}'.format(k=list_key,
                                                    c=channel_key,
                                                    d=channel_key,
                                                    s=show_progress_bar))

        range_function = cli.terminal.Progress.range if show_progress_bar else range
        self.publish(channel_key, docs_to_publish, range_function)

        lpl.info('Published {} documents'.format(str(len(docs_to_publish))))
Esempio n. 4
0
    def trim_keys(self, key_pattern, docs_to_kept_count):
         # Get all keys that match the parttern
        for list_key in self.redis_conf.scan_iter(key_pattern):

            lpl.info('List name : {l}, Docs to keep {d}'.format(
                l=list_key, d=abs(docs_to_kept_count)))
            old_list_length = self.redis_conf.llen(list_key)
            lpl.info('Key {k} contains {o} documents'.format(
                k=list_key, o=old_list_length))

            self.trim_key(list_key, docs_to_kept_count)

            new_list_length = self.redis_conf.llen(list_key)
            lpl.info('Key {k} contains {n} documents'.format(
                k=list_key, n=new_list_length))

            docs_deleted_count = old_list_length - new_list_length
            lpl.info('Deleted {d} documents from {k}'.format(
                d=docs_deleted_count, k=list_key))