def run(self, *args, **kwargs): """ Goes into infinite blocking listener() loop """ callback = { S1.msg_update(): self._on_update, S1.msg_validate(): self._on_validate, S1.msg_register(): self._on_register, } self.listener( [S1.poller_channel_name('all'), S1.poller_channel_name(self.name)], callback)
def run(self, *args, **kwargs): self.logger.info('Publisher [{0}], starting...'.format(self.name)) callback = { S1.msg_publish(): self._on_publish_updates, S1.msg_register(): self._on_register, S1.msg_update_avatar(): self._on_update_avatar, } channels = [S1.publisher_channel_name('all'), S1.publisher_channel_name(self.name)] channels.extend([name for name in self.providers.keys() if name != self.name]) # this will start infinite loop (in Pubsub) self.listener(channels, callback) self.logger.warning('Publisher [{0}], listener exit!'.format(self.name))
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S') logger = logging.getLogger(__name__) logger.addHandler( config.getLogHandler(os.path.join(args.log_path, 'poller_test.log'))) logger.level = logging.DEBUG db = data.Data(logger, args.redis_host, args.redis_port, args.redis_db) while True: logger.warning( 'Invoking registration for all, next poll in {0} seconds'.format( args.period)) with open(args.gid_set) as f_set: gid_set = [gid.strip() for gid in f_set.readlines()] logger.info('Read [{0}] gids'.format(len(gid_set))) for n in range(0, len(gid_set)): gid = gid_set[randint(0, len(gid_set) - 1)] logger.info('Invoking registration for [{0}]'.format(gid)) db.pubsub.broadcast_command(S1.publisher_channel_name('twitter'), S1.msg_register(), gid) t = randint(5, 20) logger.info('Sleeping for [{0}]'.format(t)) time.sleep(t) #get delay and wait time.sleep(args.period)
def register_gid(self, gid): # add to balance list self.rc.sadd(S1.register_set(), gid) # notify poller(s) self.pubsub.broadcast_command_now(S1.poller_channel_name('all'), S1.msg_register())