Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SessionTimer model #5668

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions temba/flows/migrations/0338_sessiontimer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.1.2 on 2024-11-20 15:09

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


class Migration(migrations.Migration):

dependencies = [
("flows", "0337_alter_flowstart_status"),
]

operations = [
migrations.CreateModel(
name="SessionTimer",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("type", models.CharField(choices=[("T", "Timeout"), ("E", "Expiration")], max_length=1)),
("time", models.DateTimeField()),
(
"session",
models.ForeignKey(
db_index=False,
on_delete=django.db.models.deletion.PROTECT,
related_name="timers",
to="flows.flowsession",
),
),
],
options={
"indexes": [models.Index(fields=["time"], name="flows_sessi_time_c44534_idx")],
"constraints": [models.UniqueConstraint(fields=("session", "type"), name="session_timer_unique")],
},
),
]
20 changes: 20 additions & 0 deletions temba/flows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,26 @@ class Meta:
]


class SessionTimer(models.Model):
"""
A scheduled timed event for a session
"""

TYPE_TIMEOUT = "T"
TYPE_EXPIRATION = "E"
TYPE_CHOICES = ((TYPE_TIMEOUT, "Timeout"), (TYPE_EXPIRATION, "Expiration"))

session = models.ForeignKey(FlowSession, on_delete=models.PROTECT, related_name="timers", db_index=False)
type = models.CharField(max_length=1, choices=TYPE_CHOICES)
time = models.DateTimeField()

class Meta:
indexes = [models.Index(fields=["time"])]
constraints = [
models.UniqueConstraint(fields=("session", "type"), name="session_timer_unique"),
]


class FlowRun(models.Model):
"""
A single contact's journey through a flow. It records the path taken, results collected etc.
Expand Down
Loading