From c73cdc50eec39461263205be2e6dcfbfbcedb7f5 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 16 Aug 2021 09:57:11 -0500 Subject: [PATCH 1/3] Re-add QUEUED status for channel connections --- .../migrations/0133_auto_20210816_1458.py | 38 +++++++++++++++++++ temba/channels/models.py | 4 +- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 temba/channels/migrations/0133_auto_20210816_1458.py diff --git a/temba/channels/migrations/0133_auto_20210816_1458.py b/temba/channels/migrations/0133_auto_20210816_1458.py new file mode 100644 index 00000000000..6ce23d9f612 --- /dev/null +++ b/temba/channels/migrations/0133_auto_20210816_1458.py @@ -0,0 +1,38 @@ +# Generated by Django 3.2.6 on 2021-08-16 14:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("channels", "0132_auto_20210813_2153"), + ] + + operations = [ + migrations.AlterField( + model_name="channelconnection", + name="error_reason", + field=models.CharField( + choices=[("P", "Provider"), ("B", "Busy"), ("N", "No Answer"), ("M", "Answering Machine")], + max_length=1, + null=True, + ), + ), + migrations.AlterField( + model_name="channelconnection", + name="status", + field=models.CharField( + choices=[ + ("P", "Pending"), + ("Q", "Queued"), + ("W", "Wired"), + ("I", "In Progress"), + ("D", "Complete"), + ("E", "Errored"), + ("F", "Failed"), + ], + max_length=1, + ), + ), + ] diff --git a/temba/channels/models.py b/temba/channels/models.py index 23c27074f31..6e17684c7ca 100644 --- a/temba/channels/models.py +++ b/temba/channels/models.py @@ -1697,6 +1697,7 @@ class ChannelConnection(models.Model): DIRECTION_CHOICES = ((DIRECTION_INCOMING, "Incoming"), (DIRECTION_OUTGOING, "Outgoing")) STATUS_PENDING = "P" # used for initial creation in database + STATUS_QUEUED = "Q" # used when we need to throttle requests for new calls STATUS_WIRED = "W" # the call has been requested on the IVR provider STATUS_IN_PROGRESS = "I" # the call has been answered STATUS_COMPLETED = "D" # the call was completed successfully @@ -1704,6 +1705,7 @@ class ChannelConnection(models.Model): STATUS_FAILED = "F" # permanent failure STATUS_CHOICES = ( (STATUS_PENDING, _("Pending")), + (STATUS_QUEUED, _("Queued")), (STATUS_WIRED, _("Wired")), (STATUS_IN_PROGRESS, _("In Progress")), (STATUS_COMPLETED, _("Complete")), @@ -1715,13 +1717,11 @@ class ChannelConnection(models.Model): ERROR_BUSY = "B" ERROR_NOANSWER = "N" ERROR_MACHINE = "M" - ERROR_THROTTLED = "T" ERROR_CHOICES = ( (ERROR_PROVIDER, _("Provider")), # an API call to the IVR provider returned an error (ERROR_BUSY, _("Busy")), # the contact couldn't be called because they're busy (ERROR_NOANSWER, _("No Answer")), # the contact didn't answer the call (ERROR_MACHINE, _("Answering Machine")), # the call went to an answering machine - (ERROR_THROTTLED, _("Throttled")), # the request to the provider to start the call has been throttled ) org = models.ForeignKey(Org, on_delete=models.PROTECT) From 7f3ce9fa58a721987b01eeabdbc41f95f8a62a3a Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 17 Aug 2021 11:31:32 -0500 Subject: [PATCH 2/3] Drop retry_count, make error_count non-null --- ...to_20210816_1458.py => 0133_auto_20210817_1631.py} | 11 ++++++++++- temba/channels/models.py | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) rename temba/channels/migrations/{0133_auto_20210816_1458.py => 0133_auto_20210817_1631.py} (75%) diff --git a/temba/channels/migrations/0133_auto_20210816_1458.py b/temba/channels/migrations/0133_auto_20210817_1631.py similarity index 75% rename from temba/channels/migrations/0133_auto_20210816_1458.py rename to temba/channels/migrations/0133_auto_20210817_1631.py index 6ce23d9f612..baccfc94bbc 100644 --- a/temba/channels/migrations/0133_auto_20210816_1458.py +++ b/temba/channels/migrations/0133_auto_20210817_1631.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.6 on 2021-08-16 14:58 +# Generated by Django 3.2.6 on 2021-08-17 16:31 from django.db import migrations, models @@ -10,6 +10,15 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RemoveField( + model_name="channelconnection", + name="retry_count", + ), + migrations.AlterField( + model_name="channelconnection", + name="error_count", + field=models.IntegerField(default=0), + ), migrations.AlterField( model_name="channelconnection", name="error_reason", diff --git a/temba/channels/models.py b/temba/channels/models.py index 6e17684c7ca..1392c5e215c 100644 --- a/temba/channels/models.py +++ b/temba/channels/models.py @@ -1741,11 +1741,9 @@ class ChannelConnection(models.Model): duration = models.IntegerField(null=True) # in seconds error_reason = models.CharField(max_length=1, null=True, choices=ERROR_CHOICES) - error_count = models.IntegerField(null=True) + error_count = models.IntegerField(default=0) next_attempt = models.DateTimeField(null=True) - retry_count = models.IntegerField(null=True) # TODO deprecate in favor of error_count - def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -1804,6 +1802,7 @@ def release(self): class Meta: indexes = [ + # used by mailroom to fetch calls that need to be retried models.Index( name="channelconnection_ivr_to_retry", fields=["next_attempt"], From 1909239460f726bbdba9622f573d0e9de9808ef6 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 17 Aug 2021 11:58:58 -0500 Subject: [PATCH 3/3] Fix test --- temba/tests/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/temba/tests/base.py b/temba/tests/base.py index 16abd027847..674cf7a17ea 100644 --- a/temba/tests/base.py +++ b/temba/tests/base.py @@ -458,7 +458,6 @@ def create_incoming_call(self, flow, contact, status=IVRCall.STATUS_COMPLETED): contact_urn=contact.get_urn(), status=status, duration=15, - retry_count=0, ) session = FlowSession.objects.create(uuid=uuid4(), org=contact.org, contact=contact, connection=call) FlowRun.objects.create(org=self.org, flow=flow, contact=contact, connection=call, session=session)