(self, msg_couch_id)
Creates billable in db that contains price of the message
    default_retry_delay/max_retries are set based on twilio support numbers:
    Most messages will have a price within 2 hours of delivery, all within 24 hours max
Creates billable in db that contains price of the message
    default_retry_delay/max_retries are set based on twilio support numbers:
    Most messages will have a price within 2 hours of delivery, all within 24 hours max
Creates billable in db that contains price of the message default_retry_delay / max_retries are set based on twilio support numbers : Most messages will have a price within 2 hours of delivery all within 24 hours max
def store_billable(self, msg_couch_id):
    """
    Creates billable in db that contains price of the message
    default_retry_delay/max_retries are set based on twilio support numbers:
    Most messages will have a price within 2 hours of delivery, all within 24 hours max
    """
    msg = SMS.objects.get(couch_id=msg_couch_id)
    if not isinstance(msg, SMS):
        raise Exception("Expected msg to be an SMS")

    if msg.couch_id and not SmsBillable.objects.filter(log_id=msg.couch_id).exists():
        try:
            msg.text.encode('iso-8859-1')
            msg_length = 160
        except UnicodeEncodeError:
            # This string contains unicode characters, so the allowed
            # per-sms message length is shortened
            msg_length = 70
        try:
            SmsBillable.create(
                msg,
                multipart_count=int(math.ceil(len(msg.text) / msg_length)),
            )
        except RetryBillableTaskException as e:
            # WARNING: Please do not remove messages from this queue
            # unless you have a backup plan for how to process them
            # before the end of the month billing cycle. If not, LEAVE AS IS.
            self.retry(exc=e)
def store_billable ( self , msg_couch_id ) : msg = SMS . objects . get ( couch_id = msg_couch_id ) if not isinstance ( msg , SMS ) : raise Exception ( "Expected msg to be an SMS" ) if msg . couch_id and not SmsBillable . objects . filter ( log_id = msg . couch_id ) . exists ( ) : try : msg . text . encode ( 'iso-8859-1' ) msg_length = 160 except UnicodeEncodeError : # This string contains unicode characters, so the allowed # per-sms message length is shortened msg_length = 70 try : SmsBillable . create ( msg , multipart_count = int ( math . ceil ( len ( msg . text ) / msg_length ) ) , ) except RetryBillableTaskException as e : # WARNING: Please do not remove messages from this queue # unless you have a backup plan for how to process them # before the end of the month billing cycle. If not, LEAVE AS IS. self . retry ( exc = e )