def add(self, host, cmd): payload = { 'host' : host, 'cmd' : cmd } queue = Queue(self.name, get_redis_master()) queue.put(payload)
class InternalCommandQueue(object): """ Command queue used to store commands that can be asynchronously processed. Commands are put to redis master and read & processed on slaves. """ name = 'task_queue' def __init__(self, redis_server=None): self.queue = Queue(self.name, server=redis_server or get_redis_slave()) def process(self): try: # we are executing outside the context of a request so # get host from payload # { # 'host' : 'localhost', # 'cmd' : 'delete/module?name=amadeus' # } num_cmds = len(self.queue) if num_cmds: log.debug('found {0} commands on queue'.format(num_cmds)) while 1: cmd = self.queue.get(1) if not cmd: break log.debug('found command: {0}'.format(cmd)) self.run_cmd(cmd) except Exception, e: log.error(u"error processing command queue: {0}".format(e), exc_info=True)
def _makeOne(self): from stubo.cache.queue import Queue import redis q = Queue('_testq', redis.Redis('localhost')) return q
def add(self, host, cmd): payload = {'host': host, 'cmd': cmd} queue = Queue(self.name, get_redis_master()) queue.put(payload)
def __init__(self, redis_server=None): self.queue = Queue(self.name, server=redis_server or get_redis_slave())
def remove(self, module_name): key = self.key(module_name) log.debug('remove {0} module from cache'.format(key)) return Queue(key, server=get_redis_server(local=False)).delete()
def get_source(self, module_name, version=None): key = self.key(module_name) q = Queue(key) version = version or len(q) return q.get_item(version-1)
def add(self, module_name, code): key = self.key(module_name) log.debug('add {0} module to cache'.format(key)) q = Queue(key, server=get_redis_server(local=False)) q.put(code)
def latest_version(self, module_name): q = Queue(self.key(module_name)) return len(q)