Beispiel #1
0
    def __init__(self, redis_host, redis_port, redis_pool, redis_db):

        db = cyclone.redis.lazyConnectionPool(redis_host,
                                              redis_port,
                                              poolsize=redis_pool,
                                              dbid=redis_db)

        self.oper = core.RedisOperations(db)
Beispiel #2
0
class Collectd(web.Application):
    def __init__(self, acl_file, redis_host, redis_port, redis_pool, redis_db):
        handlers = [
            (r"/", web.IndexHandler),
            (r"/q/(.*)", web.RestQueueHandler),
            (r"/c/(.*)", web.CometQueueHandler),
            (r"/p/(.*)", web.PolicyQueueHandler),
            (r"/j/(.*)", web.JobQueueInfoHandler),
            (r"/stats/(.*)", web.StatusHandler),
            (r"/queue", web.QueueHandler),
            (r"/control/(.*)", web.QueueControlHandler),
            (r"/ws/(.*)", web.WebSocketQueueHandler),
        ]

        handlers.append((r"/collectd/(.*)", CollectdRestQueueHandler))

        try:
            acl = web.ACL(acl_file)
        except Exception, e:
            log.msg("ERROR: Cannot load ACL file: %s" % e)
            raise RuntimeError("Cannot load ACL file: %s" % e)

        db = cyclone.redis.lazyRedisConnectionPool(redis_host,
                                                   redis_port,
                                                   pool_size=redis_pool,
                                                   db=redis_db)

        oper = core.RedisOperations(db)
        cwd = os.path.dirname(__file__)

        settings = {
            "db": db,
            "acl": acl,
            "oper": oper,
            "comet": web.CometDispatcher(oper),
            "static_path": os.path.join(cwd, "static"),
            "template_path": os.path.join(cwd, "templates"),
        }

        cyclone.web.Application.__init__(self, handlers, **settings)
Beispiel #3
0
class Application(cyclone.web.Application):
    def __init__(self, acl_file, redis_host, redis_port, redis_pool, redis_db):
        handlers = [
            (r"/",       IndexHandler),
            (r"/q/(.*)", RestQueueHandler),
            (r"/c/(.*)", CometQueueHandler),
            (r"/p/(.*)", PolicyQueueHandler),
            (r"/j/(.*)", JobQueueInfoHandler),
            (r"/stats/(.*)",  StatusHandler),
            (r"/queue",  QueueHandler),
            (r"/control/(.*)",  QueueControlHandler),
            (r"/ws/(.*)",  WebSocketQueueHandler),
        ]

        try:
            acl = ACL(acl_file)
        except Exception, e:
            log.msg("ERROR: Cannot load ACL file: %s" % e)
            raise RuntimeError("Cannot load ACL file: %s" % e)

        db = cyclone.redis.lazyConnectionPool(
            redis_host, redis_port,
            poolsize=redis_pool, dbid=redis_db)

        oper = core.RedisOperations(db)

        settings = {
            "db": db,
            "acl": acl,
            "oper": oper,
            "comet": CometDispatcher(oper),
            "static_path": pkg.resource_filename('restmq', 'static'),
            "template_path": pkg.resource_filename('restmq', 'templates'),
        }

        cyclone.web.Application.__init__(self, handlers, **settings)
Beispiel #4
0
QUEUENAME = 'test'


@defer.inlineCallbacks
def test_operations(opt, args):
    """ 
        test and docs for a redis based queue engine in python
        based on tx-redis
    """
    try:
        rd = yield cyclone.redis.RedisConnectionPool()
    except Exception, e:
        print "Error creating redis pool %s" % e
        defer.returnValue(None)

    ro = core.RedisOperations(rd)

    if opt.producer == True:
        print "Running as producer"
        uuid = yield ro.queue_add(QUEUENAME, json.dumps({'value': 'a value'}))
        print 'uuid: %s' % uuid

    if opt.consumer == True:
        print "Running as consumer"
        (policy, ret) = yield ro.queue_get(QUEUENAME)
        if ret != None:
            print "value: %s" % ret['value']  #json.loads(ret['value'])
            print "policy: %s" % policy
        else:
            print 'empty queue'