def worker_request(data):
    print 'SocketIO worker update -', data
    socketio_server.emit(
        'new_update',
        data['msg'] + ' at ' + data['timestamp'],
        namespace='/browser',
    )
def worker_request(data):
    print('SocketIO worker update -', data)
    socketio_server.emit(
        'new_update',
        data['msg'] + ' at ' + data['timestamp'],
        namespace='/browser',
    )
def listen_thread():
    r = redis.StrictRedis()
    pubsub = r.pubsub()
    pubsub.subscribe([config.REDIS_CHANNEL])
    for item in pubsub.listen():
        if item['data'] == "KILL":
            pubsub.unsubscribe()
            print 'REDIS - unsubscribed and finished'
            break
        elif item['data'] != 1:
            print 'REDIS -', item['channel'], ":", item['data']
            with webapp.app_context():
                data = json.loads(item['data'])
                socketio.emit(
                    'new_update',
                    data['msg'] + ' at ' + data['timestamp'],
                    namespace='/browser',
                )
def listen_thread():
    r = redis.StrictRedis()
    pubsub = r.pubsub()
    pubsub.subscribe([config.REDIS_CHANNEL])
    for item in pubsub.listen():
        if item['data'] == "KILL":
            pubsub.unsubscribe()
            print('REDIS - unsubscribed and finished')
            break
        elif item['data'] != 1:
            print('REDIS -', item['channel'], ":", item['data'])
            with webapp.app_context():
                data = json.loads(item['data'])
                socketio.emit(
                    'new_update',
                    data['msg'] + ' at ' + data['timestamp'],
                    namespace='/browser',
                )
def listen_thread():
    ctx = zmq.Context()
    # Reply - act as server
    socket = ctx.socket(zmq.REP)
    socket.bind('tcp://*:%s' % config.ZEROMQ_PORT)
    while True:
        request = socket.recv()
        print 'ZEROMQ request -', request
        socket.send('OK')

        if request == 'KILL':
            socket.close()
            print 'Socket closed.'
            break

        with webapp.app_context():
            data = json.loads(request)
            print 'Sending to SocketIO ...'
            socketio.emit(
                'new_update',
                data['msg'] + ' at ' + data['timestamp'],
                namespace='/browser',
            )
예제 #6
0
def listen_thread():
    ctx = zmq.Context()
    # Reply - act as server
    socket = ctx.socket(zmq.REP)
    socket.bind('tcp://*:%s' % config.ZEROMQ_PORT)
    while True:
        request = socket.recv()
        print('ZEROMQ request -', request)
        socket.send('OK')

        if request == 'KILL':
            socket.close()
            print('Socket closed.')
            break

        with webapp.app_context():
            data = json.loads(request)
            print('Sending to SocketIO ...')
            socketio.emit(
                'new_update',
                data['msg'] + ' at ' + data['timestamp'],
                namespace='/browser',
            )