def remove_from_queue(queued_sms): with transaction.atomic(): sms = SMS() for field in sms._meta.fields: if field.name != 'id': setattr(sms, field.name, getattr(queued_sms, field.name)) queued_sms.delete() sms.save() sms.publish_change() if sms.direction == OUTGOING and sms.processed and not sms.error: create_billable_for_sms(sms) elif sms.direction == INCOMING and sms.domain and domain_has_privilege(sms.domain, privileges.INBOUND_SMS): create_billable_for_sms(sms)
def remove_from_queue(queued_sms): with transaction.atomic(): sms = SMS() for field in sms._meta.fields: if field.name != 'id': setattr(sms, field.name, getattr(queued_sms, field.name)) queued_sms.delete() sms.save() sms.publish_change() if sms.direction == OUTGOING and sms.processed and not sms.error: create_billable_for_sms(sms) datadog_counter('commcare.sms.outbound_succeeded') elif sms.direction == OUTGOING: datadog_counter('commcare.sms.outbound_failed') elif sms.direction == INCOMING and sms.domain and domain_has_privilege( sms.domain, privileges.INBOUND_SMS): create_billable_for_sms(sms)
def remove_from_queue(queued_sms): with transaction.atomic(): sms = SMS() for field in sms._meta.fields: if field.name != 'id': setattr(sms, field.name, getattr(queued_sms, field.name)) queued_sms.delete() sms.save() sms.publish_change() tags = {'backend': sms.backend_api, 'icds_indicator': ''} if isinstance(sms.custom_metadata, dict) and 'icds_indicator' in sms.custom_metadata: tags.update({'icds_indicator': sms.custom_metadata['icds_indicator']}) if sms.direction == OUTGOING and sms.processed and not sms.error: create_billable_for_sms(sms) metrics_counter('commcare.sms.outbound_succeeded', tags=tags) elif sms.direction == OUTGOING: metrics_counter('commcare.sms.outbound_failed', tags=tags) elif sms.direction == INCOMING and sms.domain and domain_has_privilege( sms.domain, privileges.INBOUND_SMS): create_billable_for_sms(sms)