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)
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)
def fire_follow_triggers(channel_id, contact_urn_id, new_mage_contact=False): """ Fires a follow trigger """ urn = ContactURN.objects.select_related('contact').get(pk=contact_urn_id) contact = urn.contact # for now, flows start against contacts rather than URNs # if contact was just created in Mage then.. # * its dynamic groups won't have been initialized # * we need to update our cached contact counts if new_mage_contact: mage_handle_new_contact(contact.org, contact) Trigger.catch_triggers(contact, FOLLOW_TRIGGER, channel_id=channel_id)
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))
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)