views:

60

answers:

0

I have a view function which needs to perform an xmlrpc call to my engine which runs on twisted. I have googled around for something like that, but there doesn't seem to be any material on django + xmlrpc CLIENT (there's tons of literature on xmlrpc server + django).

The reason behind this is because I am not really familiar with WSGI and attaching django on it looks really like a hack rather than something that is stable etc. (Correct me if I am wrong, but I plan to use django on nginx, separating components of different logic makes it easier to scale too {and don't say it's premature optimization, it's just something to bare in mind while constructing code })

I was thinking of doing something like that in my views.py:

engine_xmlrpc_server = ServerProxy(("localhost", 12345))

def subscribe_user_to_channel(request):
    """@for now, we will assume that it's just simple messaging and pushing to all
    METHOD
        post from AJAX
    PARAMS 
        1) sessionid, str
        2) message, str
    RETURNS
        1 or 0, *since this call is just posting, 1 or 0 indicates error or successs*
    """
    global engine_xmlrpc_server

    if request.method != "POST":
        return 'POST ONLY'
    try:
        sessionid = request.POST.get( 'sessionid')
        channel = request.POST.get( 'channel')
    except ValueError:
        return "'sessionid' and 'body' are required"

    result = engine_xmlrpc_server.subscribe_user_to_channel( sessionid, channel)
    if result == E.FULL:
        return "Rooms are full"
    elif result == E.SUCCESS:
        return 1
    return 0

Note that this is not a chat room, so don't bother recommending me to use jabber or STOMP etc.

I am familiar with making this call async, like using celery. But since I have to return a result anyway, why bother making it async? (since the request has to wait nontheless)