Exemple #1
0
def notice_listener(user, context, interval=1):
    while True:
        notices = get_notices(user)
        if notices:
            yield JSONEncoder().encode({'notices': notices})
            raise StopIteration()

        yield ''
        uwsgi.green_pause(1)
def handler(id):
    id = int(id)
    if not event or event[1] <= id:
        uwsgi.green_pause(60)
    myevent = event
    eventid = myevent[1]
    levent = [x[1] for x in myevent[0] if x[0] >= id]
    levent = set(levent)
    yield "\n".join(levent) + "\n!%s" % eventid
def handler(id):
    id = int(id)
    if not event or event[1] <= id:
        uwsgi.green_pause(60)
    myevent = event
    eventid = myevent[1]
    levent = [x[1] for x in myevent[0] if x[0] >= id]
    levent = set(levent)
    yield "\n".join(levent) + "\n!%s" % eventid
def handler(id):
    userid = bottle.request.GET.get('uid', None)
    if userid and secret:
        hash = hashlib.sha1("%s.%s" % (userid, secret)).hexdigest()
        sign = bottle.request.GET.get('sign', "NA")
        if hash != sign:
            userid = None
    id = int(id)
    if not event or event[1] <= id:
        uwsgi.green_pause(50 + random.randint(0,20) ) #Try to stop all from being "done" and re-request at the same time
    myevent = event
    eventid = myevent[1]
    levent = [x[1] for x in myevent[0] if x[0] > id and (x[2] == "N" or (userid and x[2] == int(userid)))]
    levent = set(levent)
    #yield "eval://Error no id : %s\n" % str(myevent) + "\n".join(levent) + "\n!%s" % eventid
    yield "\n" + "\n".join(levent) + "\n!%s" % eventid
Exemple #5
0
def recv():
    response.header['Transfer-Encoding'] = 'chunked'

    # this will flush headers
    yield ""

    running = True
    while running:
        # this will put the core in pause (for max 10 seconds) and remove it from the sched queue, so the /send can write to its socket
        if not uwsgi.green_pause(10):
            running = False
        # this will maintain the connection opened if no data arrives
        yield "<span/>"
Exemple #6
0
def handler (id):
    global event

    # Validate user signature
    userid = bottle.request.GET.get ('uid', None)
    if userid and secret:
        hash = hashlib.sha1("%s.%s" % (userid, secret)).hexdigest()
        sign = bottle.request.GET.get ('sign', "NA")
        if hash != sign:
            userid = None

    id = int (id)

    LOCK.acquire()
    myevent = event # We don't want update in a middle...'
    LOCK.release()

    # Event format: (list of events, recent event id)

    # Lets sleep for awhile in case there is no interesting events
    if not myevent or myevent[1] <= id:
        uwsgi.green_pause(50 + random.randint(0,20) ) #Try to stop all from being "done" and re-request at the same time

    LOCK.acquire()
    myevent = event
    LOCK.release()

    # One more try
    if not myevent:
        yield ""
    else:
        eventid = myevent[1]
        levent = [x[1] for x in myevent[0] if x[0] > id and (x[2] == "N" or (userid and x[2] == int(userid)))]
        levent = set(levent)

        #yield "\n".join(levent) + "\n!%s" % eventid
        #yield "eval://Error no id : %s\n" % str(myevent) + "\n".join(levent) + "\n!%s" % eventid
        yield "\n" + "\n".join(levent) + "\n!%s" % eventid
def handler (id):
    global event

    # Validate user signature
    userid = bottle.request.GET.get ('uid', None)
    if userid and secret:
        hash = hashlib.sha1("%s.%s" % (userid, secret)).hexdigest()
        sign = bottle.request.GET.get ('sign', "NA")
        if hash != sign:
            userid = None

    id = int (id)

    LOCK.acquire()
    myevent = event # We don't want update in a middle...'
    LOCK.release()

    # Event format: (list of events, recent event id)

    # Lets sleep for awhile in case there is no interesting events
    if not myevent or myevent[1] <= id:
        uwsgi.green_pause (60)

    LOCK.acquire()
    myevent = event
    LOCK.release()

    # One more try
    if not myevent:
        yield ""
    else:
        eventid = myevent[1]
        levent = [x[1] for x in myevent[0] if x[0] > id and (x[2] == "N" or (userid and x[2] == int(userid)))]
        levent = set(levent)

        yield "\n".join(levent) + "\n!%s" % eventid