Example #1
0
def application(e, s):

    node = uwsgi.cluster_best_node()
    print(node)

    if not node:
        print("sorry node unavailable")
        raise StopIteration

    for part in uwsgi.send_message(node, 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()):
        yield part
Example #2
0
def application(e,s):

	node = uwsgi.cluster_best_node()
	print node

	if not node:
		print "sorry node unavailable"
		raise StopIteration

	for part in uwsgi.send_message(node, 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()):
		yield part 
Example #3
0
def put_file(env, start_response, volume, collection, key):
    f = env['wsgi.input']
    fd = f.fileno()
    toread = uwsgi.cl()
    tmpf = None
    crc = 0
    if toread < RSIZE:
        data = f.read()
        crc = crc32(data, crc)
        buf = StringIO(data)
    else:
        buf = StringIO()
        sz = 0
        tmpname = volume.tmpname()
        while toread > 0:
            yield uwsgi.wait_fd_read(fd, 30)
            data = f.read(min(toread, RSIZE))
            rbytes = len(data)
            toread -= rbytes
            sz += rbytes
            crc = crc32(data, crc)
            buf.write(data)
            if sz > WSIZE:
                if not tmpf:
                    tmpf = open(tmpname, 'wb')
                tmpf.write(buf.getvalue())
                buf = StringIO()
                sz = 0

    if tmpf:
        if sz:
            tmpf.write(buf.getvalue())
        tmpf.close()
        fobj = tmpname
    else:
        buf.seek(0)
        fobj = buf

    meta = {'crc': crc & 0xffffffff}
    if 'CONTENT_TYPE' in env:
        meta['ct'] = env['CONTENT_TYPE']

    volume.put(collection, key, fobj, meta)

    start_response('200 OK', [('Content-Type', 'text/plain')])
    yield 'Ok'
Example #4
0
def application(e, s):

    global current_node

    nodes = uwsgi.cluster_nodes()
    print(nodes)

    if len(nodes) == 0:
        print("no cluster node available")
        raise StopIteration

    if current_node >= len(nodes):
        current_node = 0

    node = nodes[current_node]

    for part in uwsgi.send_message(node, 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()):
        yield part

    current_node += 1
Example #5
0
def application(e, s):

    global current_node

    nodes = uwsgi.cluster_nodes()
    print nodes

    if len(nodes) == 0:
        print "no cluster node available"
        raise StopIteration

    if current_node >= len(nodes):
        current_node = 0

    node = nodes[current_node]

    for part in uwsgi.send_message(node, 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()):
        yield part

    current_node += 1
Example #6
0
def application(env, start_response):

    # open the socket
    fd = uwsgi.async_connect("192.168.173.100:3032")

    # wait for connection ready (3s timeout)
    yield uwsgi.wait_fd_write(fd, 3)

    # has timed out ?
    if env['x-wsgiorg.fdevent.timeout']:
        print "connection timed out !!!"
        uwsgi.close(fd)
        raise StopIteration

    # connection refused ?
    if not uwsgi.is_connected(fd):
        print "unable to connect"
        uwsgi.close(fd)
        raise StopIteration

    # send request
    # env can contains python objects, but send_message will discard them.
    # In this way we will automagically have a congruent and valid uwsgi packet
    uwsgi.async_send_message(fd, 0, 0, env)

    # send the http body
    # ready body in async mode and resend to fd
    # uwsgi.recv will use always an internal buffer of 4096, but can be limited in the number of bytes to read

    # does this request has a body ?
    cl = uwsgi.cl()

    if cl > 0:
        # get the input fd
        input = env['wsgi.input'].fileno()

        # read (in async mode) upto 'cl' data and send to uwsgi peer
        while cl > 0:
            bufsize = min(cl, 4096)
            yield uwsgi.wait_fd_read(input, 30)
            if env['x-wsgiorg.fdevent.timeout']:
                print "connection timed out !!!"
                uwsgi.close(fd)
                raise StopIteration
            body = uwsgi.recv(input, bufsize)
            if body:
                uwsgi.send(fd, body)
                cl = cl - len(body)
            else:
                break

    # wait for response (30s timeout)
    yield uwsgi.wait_fd_read(fd, 30)

    # has timed out ?
    if env['x-wsgiorg.fdevent.timeout']:
        print "connection timed out !!!"
        uwsgi.close(fd)
        raise StopIteration

    data = uwsgi.recv(fd)
    # recv the data, if it returns None the callable will end
    while data:
        yield data
        # wait for response
        yield uwsgi.wait_fd_read(fd, 30)
        if env['x-wsgiorg.fdevent.timeout']:
            print "connection timed out !!!"
            uwsgi.close(fd)
            raise StopIteration
        data = uwsgi.recv(fd)

    uwsgi.close(fd)
Example #7
0
def application(e,s):

	for part in uwsgi.send_message("192.168.173.100:3032", 0, 0, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()):
		yield part 
Example #8
0
def application(e,s):

	for part in uwsgi.send_message(fd, 0, 4, e, 30, e['wsgi.input'].fileno(), uwsgi.cl()):
		yield part 
Example #9
0
def application(e, s):

    for part in uwsgi.send_message("192.168.173.100:3032", 0, 0, e, 0,
                                   e['wsgi.input'].fileno(), uwsgi.cl()):
        yield part
Example #10
0
def application(e, s):

    for part in uwsgi.send_message(fd, 0, 4, e, 30, e['wsgi.input'].fileno(),
                                   uwsgi.cl()):
        yield part