Example #1
0
def process_message_task(msg_id, from_mage=False, new_contact=False):
    """
    Processes a single incoming message through our queue.
    """
    r = get_redis_connection()
    msg = Msg.objects.filter(pk=msg_id, status=PENDING).select_related(
        'org', 'contact', 'contact_urn', 'channel').first()

    # somebody already handled this message, move on
    if not msg:  # pragma: needs cover
        return

    # get a lock on this contact, we process messages one by one to prevent odd behavior in flow processing
    key = 'pcm_%d' % msg.contact_id
    if not r.get(key):
        with r.lock(key, timeout=120):
            print "M[%09d] Processing - %s" % (msg.id, msg.text)
            start = time.time()

            # if message was created in Mage...
            if from_mage:
                mage_handle_new_message(msg.org, msg)
                if new_contact:
                    mage_handle_new_contact(msg.org, msg.contact)

            Msg.process_message(msg)
            print "M[%09d] %08.3f s - %s" % (msg.id, time.time() - start,
                                             msg.text)
Example #2
0
def process_message_task(msg_id, from_mage=False, new_contact=False):
    """
    Processes a single incoming message through our queue.
    """
    r = get_redis_connection()
    msg = Msg.current_messages.filter(pk=msg_id, status=PENDING).select_related('org', 'contact', 'contact_urn', 'channel').first()

    # somebody already handled this message, move on
    if not msg:
        return

    # get a lock on this contact, we process messages one by one to prevent odd behavior in flow processing
    key = 'pcm_%d' % msg.contact_id
    if not r.get(key):
        with r.lock(key, timeout=120):
            print "M[%09d] Processing - %s" % (msg.id, msg.text)
            start = time.time()

            # if message was created in Mage...
            if from_mage:
                mage_handle_new_message(msg.org, msg)
                if new_contact:
                    mage_handle_new_contact(msg.org, msg.contact)

            Msg.process_message(msg)
            print "M[%09d] %08.3f s - %s" % (msg.id, time.time() - start, msg.text)
Example #3
0
def process_message(msg, from_mage=False, new_contact=False):
    """
    Processes the passed in message dealing with new contacts or mage messages appropriately.
    """
    print("M[%09d] Processing - %s" % (msg.id, msg.text))
    start = time.time()

    # if message was created in Mage...
    if from_mage:
        mage_handle_new_message(msg.org, msg)
        if new_contact:
            mage_handle_new_contact(msg.org, msg.contact)

    Msg.process_message(msg)
    print("M[%09d] %08.3f s - %s" % (msg.id, time.time() - start, msg.text))
Example #4
0
def process_message_task(msg_id, from_mage=False, new_contact=False):
    """
    Processses a single incoming message through our queue.
    """
    msg = Msg.objects.filter(pk=msg_id, status=PENDING).select_related('org', 'contact', 'contact__urns').first()

    # somebody already handled this message, move on
    if not msg:
        return

    # if message was created in Mage...
    if from_mage:
        mage_handle_new_message(msg.org, msg)
        if new_contact:
            mage_handle_new_contact(msg.org, msg.contact)

    Msg.process_message(msg)
Example #5
0
def process_message_task(msg_id, from_mage=False, new_contact=False):
    """
    Processses a single incoming message through our queue.
    """
    msg = Msg.objects.filter(pk=msg_id, status=PENDING).select_related('org', 'contact', 'contact__urns').first()

    # somebody already handled this message, move on
    if not msg:
        return

    # if message was created in Mage...
    if from_mage:
        mage_handle_new_message(msg.org, msg)
        if new_contact:
            mage_handle_new_contact(msg.org, msg.contact)

    Msg.process_message(msg)