Skip to content

Commit

Permalink
Add new generic model for scheduled contact events like session timeo…
Browse files Browse the repository at this point in the history
…uts etc
  • Loading branch information
rowanseymour committed Jan 17, 2025
1 parent 4e5c40e commit a35b422
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
43 changes: 43 additions & 0 deletions temba/contacts/migrations/0199_contactfire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 5.1.4 on 2025-01-17 14:24

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("contacts", "0198_squashed"),
]

operations = [
migrations.CreateModel(
name="ContactFire",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
(
"fire_type",
models.CharField(choices=[("E", "Expiration"), ("T", "Timeout"), ("C", "Campaign")], max_length=1),
),
("scope", models.CharField(max_length=64)),
("when", models.DateTimeField(db_index=True)),
("extra", models.JSONField(default=dict)),
(
"contact",
models.ForeignKey(
db_index=False,
on_delete=django.db.models.deletion.PROTECT,
related_name="fires",
to="contacts.contact",
),
),
],
options={
"constraints": [
models.UniqueConstraint(
fields=("contact", "fire_type", "scope"), name="fire_contact_type_scope_unique"
)
],
},
),
]
26 changes: 26 additions & 0 deletions temba/contacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,32 @@ class Meta:
]


class ContactFire(models.Model):
"""
Something to happen to a contact in the future - processed by mailroom.
"""

TYPE_WAIT_EXPIRATION = "E"
TYPE_WAIT_TIMEOUT = "T"
TYPE_CAMPAIGN = "C"
TYPE_CHOICES = ((TYPE_WAIT_EXPIRATION, "Expiration"), (TYPE_WAIT_TIMEOUT, "Timeout"), (TYPE_CAMPAIGN, "Campaign"))

id = models.BigAutoField(auto_created=True, primary_key=True)
contact = models.ForeignKey( # indexed below
"contacts.Contact", on_delete=models.PROTECT, related_name="fires", db_index=False
)
fire_type = models.CharField(max_length=1, choices=TYPE_CHOICES)
scope = models.CharField(max_length=64) # e.g. campaign event id
when = models.DateTimeField(db_index=True)
extra = models.JSONField(default=dict)

class Meta:
constraints = [
# used to prevent adding duplicate fires for the same contact and scope
models.UniqueConstraint(name="fire_contact_type_scope_unique", fields=("contact", "fire_type", "scope"))
]


class ContactExport(ExportType):
"""
Export of contacts
Expand Down

0 comments on commit a35b422

Please sign in to comment.