<s> """<STR_LIT>""" <EOL> import redis <EOL> import logging <EOL> import threading <EOL> import sleekxmpp <EOL> from sleekxmpp . plugins . base import base_plugin <EOL> log = logging . getLogger ( __name__ ) <EOL> class redis_queue ( base_plugin ) : <EOL> def plugin_init ( self ) : <EOL> self . description = "<STR_LIT>" <EOL> self . redis = redis . Redis ( host = self . config . get ( '<STR_LIT:host>' , '<STR_LIT:localhost>' ) , <EOL> port = self . config . get ( '<STR_LIT:port>' , <NUM_LIT> ) , <EOL> db = self . config . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . _handlers = { } <EOL> def post_init ( self ) : <EOL> base_plugin . post_init ( self ) <EOL> self . process ( ) <EOL> def add_queue_handler ( self , queue , handler ) : <EOL> def process ( ) : <EOL> while not self . xmpp . stop . isSet ( ) : <EOL> _ , data = self . redis . blpop ( queue ) <EOL> handler ( data ) <EOL> self . _handlers [ queue ] = process <EOL> def process ( self ) : <EOL> for queue in self . _handlers : <EOL> log . debug ( "<STR_LIT>" % queue ) <EOL> t = threading . Thread ( name = queue , <EOL> target = self . _handlers [ queue ] ) <EOL> t . daemon = True <EOL> t . start ( ) <EOL> def queue ( self , name , value ) : <EOL> self . redis . rpush ( name , value ) </s>
