コード例 #1
0
 def add(self, host, cmd):
     payload =  { 
         'host' : host, 
         'cmd' : cmd
     } 
     queue = Queue(self.name, get_redis_master())
     queue.put(payload)              
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
 def _makeOne(self):
     from stubo.cache.queue import Queue
     import redis
     q = Queue('_testq', redis.Redis('localhost'))
     return q
コード例 #5
0
 def add(self, host, cmd):
     payload = {'host': host, 'cmd': cmd}
     queue = Queue(self.name, get_redis_master())
     queue.put(payload)
コード例 #6
0
 def __init__(self, redis_server=None):
     self.queue = Queue(self.name, server=redis_server or get_redis_slave())
コード例 #7
0
 def __init__(self, redis_server=None):
     self.queue = Queue(self.name, 
                        server=redis_server or get_redis_slave())
コード例 #8
0
 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()
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
0
 def latest_version(self, module_name):
     q = Queue(self.key(module_name))
     return len(q)