Skip to content

Commit

Permalink
Merge pull request #3496 from nyaruka/connection_status_tweak
Browse files Browse the repository at this point in the history
Final channelconnection model changes
  • Loading branch information
rowanseymour authored Aug 17, 2021
2 parents d892d06 + df568a4 commit 3783553
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
47 changes: 47 additions & 0 deletions temba/channels/migrations/0133_auto_20210817_1631.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 3.2.6 on 2021-08-17 16:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("channels", "0132_auto_20210813_2153"),
]

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",
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,
),
),
]
9 changes: 4 additions & 5 deletions temba/channels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,13 +1697,15 @@ 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
STATUS_ERRORED = "E" # temporary failure (will be retried)
STATUS_FAILED = "F" # permanent failure
STATUS_CHOICES = (
(STATUS_PENDING, _("Pending")),
(STATUS_QUEUED, _("Queued")),
(STATUS_WIRED, _("Wired")),
(STATUS_IN_PROGRESS, _("In Progress")),
(STATUS_COMPLETED, _("Complete")),
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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"],
Expand Down
1 change: 0 additions & 1 deletion temba/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3783553

Please sign in to comment.