Esempio n. 1
0
def receive_public():
    """
    Receive a public Salmon Slap and process it now.
    """
    dmp = DiasporaMessageParser(DiasporaContact.get_by_username)
    ret, c_from = dmp.decode(request.form['xml'], None)
    try:
        process_incoming_message(ret, c_from, None)
        return 'OK'
    except Exception as e:
        err = format_exc()
        current_app.logger.error(err)
        db.session.expunge_all()
        queue_item = MessageQueue()
        queue_item.local_user = None
        queue_item.remote = None
        queue_item.format = MessageQueue.PUBLIC_INCOMING
        queue_item.body = request.form['xml'].encode('ascii')
        queue_item.last_attempted_at = datetime.now()
        if not isinstance(e, TryLater):
            queue_item.error = err.encode('utf-8')
        db.session.add(queue_item)
        if isinstance(e, TryLater):
            pass
        else:
            return 'Error', 400
    finally:
        db.session.commit()

    # Sneakily attempt to process one item off the backlog
    try:
        queue_items = db.session.query(MessageQueue).filter(
            MessageQueue.Queries.pending_public_items()
        ).order_by(MessageQueue.created_at)
        MessageQueue.process_queue(queue_items, None, max_items=1)
    except:
        pass

    return 'OK'
Esempio n. 2
0
def run_public_queue(_user):
    queue_items = db.session.query(MessageQueue).filter(
        MessageQueue.Queries.pending_public_items()
    ).order_by(MessageQueue.created_at)
    MessageQueue.process_queue(queue_items, None)
    return redirect(url_for('feed.view'))