-
Notifications
You must be signed in to change notification settings - Fork 4
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 openhim queue model and signal #590
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
class EventstoreConfig(AppConfig): | ||
name = "eventstore" | ||
|
||
def ready(self): | ||
import eventstore.signals # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Generated by Django 4.1.7 on 2023-11-23 09:40 | ||
|
||
import uuid | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("eventstore", "0061_alter_optout_reason"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="OpenHIMQueue", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
("object_id", models.UUIDField()), | ||
( | ||
"object_type", | ||
models.CharField( | ||
choices=[ | ||
("PrebirthRegistration", "PrebirthRegistration"), | ||
("CHWRegistration", "CHWRegistration"), | ||
("PublicRegistration", "PublicRegistration"), | ||
("ChannelSwitch", "ChannelSwitch"), | ||
("OptOut", "OptOut"), | ||
], | ||
max_length=30, | ||
), | ||
), | ||
( | ||
"status", | ||
models.PositiveSmallIntegerField( | ||
choices=[ | ||
(0, "Pending"), | ||
(1, "Processing"), | ||
(2, "Complete"), | ||
(3, "Error"), | ||
], | ||
default=0, | ||
), | ||
), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 4.1.7 on 2023-11-23 11:40 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("eventstore", "0062_openhimqueue"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="openhimqueue", | ||
name="object_type", | ||
field=models.CharField( | ||
choices=[ | ||
("prebirth_registration", "PrebirthRegistration"), | ||
("chw_registration", "CHWRegistration"), | ||
("public_registration", "PublicRegistration"), | ||
("channel_switch", "ChannelSwitch"), | ||
("optout", "OptOut"), | ||
], | ||
max_length=30, | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1094,3 +1094,32 @@ def clean(self): | |
date(self.dob_year, self.dob_month, self.dob_day) | ||
except ValueError as e: | ||
raise ValidationError(f"Invalid date of birth date, {str(e)}") | ||
|
||
|
||
class OpenHIMQueue(models.Model): | ||
class ObjectType: | ||
PREBIRTH_REGISTRATION = "prebirth_registration" | ||
CHW_REGISTRATION = "chw_registration" | ||
PUBLIC_REGISTRATION = "public_registration" | ||
CHANNEL_SWITCH = "channel_switch" | ||
OPTOUT = "optout" | ||
choices = ( | ||
(PREBIRTH_REGISTRATION, "PrebirthRegistration"), | ||
(CHW_REGISTRATION, "CHWRegistration"), | ||
(PUBLIC_REGISTRATION, "PublicRegistration"), | ||
(CHANNEL_SWITCH, "ChannelSwitch"), | ||
(OPTOUT, "OptOut"), | ||
) | ||
|
||
class Status(models.IntegerChoices): | ||
PENDING = 0 | ||
PROCESSING = 1 | ||
COMPLETE = 2 | ||
ERROR = 3 | ||
|
||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) | ||
object_id = models.UUIDField() | ||
object_type = models.CharField(max_length=30, choices=ObjectType.choices) | ||
status = models.PositiveSmallIntegerField( | ||
choices=Status.choices, default=Status.PENDING | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need to store a copy of the details from the object? In case they do a forget delete before this gets forwarded? Or in that case do we not want to forward the object to them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I didn't think about that use case, I would assume we don't send it then, since they requested we delete all their data. We can't leave it in a queue then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noted the assumption on the ticket |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from eventstore.models import OpenHIMQueue, PrebirthRegistration | ||
|
||
|
||
@receiver(post_save, sender=PrebirthRegistration) | ||
def queue_prebirth_registration(sender, instance, created, **kwargs): | ||
if created: | ||
OpenHIMQueue.objects.create( | ||
object_id=instance.id, | ||
object_type=OpenHIMQueue.ObjectType.PREBIRTH_REGISTRATION, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big thing, but I think we usually use the snake case for these values, eg.
prebirth_registration
, for the value that gets stored in the database, and then title case for the values that get shown in the UI, eg.Prebirth Registration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review, yes that makes sense, I initially wanted to get the models dymanically so tried to keep them the same as the class name