#coding=utf-8
import time
from mq import MessageQueue
from threading import Thread, Lock

from utils import get_time
from log import get_logger

addr = {
    "host": "127.0.0.1",
    "port": 6379,
}

r = MessageQueue(**addr)
logger = get_logger('debug.log')


class SchedulerWorker(object):
    def __init__(self, queue, thread_num=5):
        r.set_queue(queue)
        self.mutex = Lock()
        self.thread_num = thread_num

    def run(self):
        self.spawn_worker()

    def spawn_worker(self):
        t_list = []
        for th_i in range(self.thread_num):
            t_threading = Thread(target=self.spawn_handler, args=())
            t_list.append(t_threading)
Exemple #2
0
    log = logging.getLogger(__name__)
    log.info(u"Server port = %d.", settings.PORT)
    log.info(u"Server addr = %s.", settings.BIND_ADDRESS)
    log.info(u"Public path = %s.", settings.PUBLIC_PATH)

    # Set up the database
    db_init(settings.DATABASE_CONFIG)

    # Just log success
    log.info(u"Init OK & server running.")

    # IO Loop for websockets and the amqp stuff
    io_loop = ioloop.IOLoop.instance()

    # Set up the message queues
    mq = MessageQueue(io_loop)
    mq.connect()

    # SockJS interface
    sockClass = UtuputkiSock
    sockClass.mq = mq
    router = SockJSRouter(sockClass, '/sock', dict(mq=mq))

    # Index and static handlers
    handlers = router.urls + [
        (r'/video/(.*)$', web.StaticFileHandler, {
            'path': settings.CACHE_DIR}),
        (r'/(.*)$', web.StaticFileHandler, {
            'path': settings.PUBLIC_PATH,
            'default_filename': 'index.html'}),
    ]
Exemple #3
0
    log = logging.getLogger(__name__)
    log.info(u"Server port = %d.", settings.PORT)
    log.info(u"Server addr = %s.", settings.BIND_ADDRESS)
    log.info(u"Public path = %s.", settings.PUBLIC_PATH)

    # Set up the database
    db_init(settings.DATABASE_CONFIG)

    # Just log success
    log.info(u"Init OK & server running.")

    # IO Loop for websockets and the amqp stuff
    io_loop = ioloop.IOLoop.instance()

    # Set up the message queues
    mq = MessageQueue(io_loop)
    mq.connect()

    # SockJS interface
    sockClass = UtuputkiSock
    sockClass.mq = mq
    router = SockJSRouter(sockClass, '/sock', dict(mq=mq))

    # Index and static handlers
    handlers = router.urls + [
        (r'/video/(.*)$', web.StaticFileHandler, {
            'path': settings.CACHE_DIR
        }),
        (r'/(.*)$', web.StaticFileHandler, {
            'path': settings.PUBLIC_PATH,
            'default_filename': 'index.html'
#coding:utf-8
import time
import random

from mq import MessageQueue

addr = {
    "host":"127.0.0.1",
    "port":6379,
    "queue":'queue'
}

r = MessageQueue(**addr)

def random_str(num):
    randomlength=num
    str = ''
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    length = len(chars) - 1
    _random = random.Random()
    for i in range(randomlength):
        str+=chars[_random.randint(0, length)]
    return str

if __name__ == "__main__":
    queue = 'queue'
    ack_queue = "ack_%s"%queue
    for _i in range(100):
        r.zadd(random_str(10),int(time.time()))
    res = r._conn.zrangebyscore(ack_queue,0,int(time.time()))
    print res