-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send high priority, transactional messages before bulk messages.
- Loading branch information
1 parent
5cb78a2
commit ad00b81
Showing
11 changed files
with
245 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/smpp_gateway/migrations/0009_remove_mtmessage_is_transactional_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.2.16 on 2024-11-12 22:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("smpp_gateway", "0008_mtmessage_is_transactional"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="mtmessage", | ||
name="is_transactional", | ||
), | ||
migrations.AddField( | ||
model_name="mtmessage", | ||
name="priority_flag", | ||
field=models.IntegerField( | ||
choices=[ | ||
(0, "Level 0 (lowest) priority"), | ||
(1, "Level 1 priority"), | ||
(2, "Level 2 priority"), | ||
(3, "Level 3 (highest) priority"), | ||
], | ||
null=True, | ||
), | ||
), | ||
] |
41 changes: 41 additions & 0 deletions
41
src/smpp_gateway/migrations/0010_remove_mtmessage_mt_message_status_idx_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Generated by Django 4.2.16 on 2024-11-13 17:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("smpp_gateway", "0009_remove_mtmessage_is_transactional_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveIndex( | ||
model_name="mtmessage", | ||
name="mt_message_status_idx", | ||
), | ||
migrations.AlterField( | ||
model_name="mtmessage", | ||
name="priority_flag", | ||
field=models.IntegerField( | ||
choices=[ | ||
(0, "Level 0 (lowest) priority"), | ||
(1, "Level 1 priority"), | ||
(2, "Level 2 priority"), | ||
(3, "Level 3 (highest) priority"), | ||
], | ||
null=True, | ||
verbose_name="priority flag", | ||
), | ||
), | ||
migrations.AddIndex( | ||
model_name="mtmessage", | ||
index=models.Index( | ||
models.F("status"), | ||
models.OrderBy( | ||
models.F("priority_flag"), descending=True, nulls_last=True | ||
), | ||
condition=models.Q(("status", "new")), | ||
name="mt_message_status_idx", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from rapidsms.messages.incoming import IncomingMessage | ||
from rapidsms.messages.outgoing import OutgoingMessage | ||
from rapidsms.router.blocking import BlockingRouter | ||
|
||
from smpp_gateway.models import MTMessage | ||
|
||
|
||
class PriorityIncomingMessage(IncomingMessage): | ||
def respond(self, text, **kwargs): | ||
fields = kwargs.get("fields", {}) | ||
if "priority_flag" not in fields: | ||
fields["priority_flag"] = MTMessage.PriorityFlag.LEVEL_2.value | ||
kwargs["fields"] = fields | ||
return super().respond(text, **kwargs) | ||
|
||
|
||
class PriorityOutgoingMessage(OutgoingMessage): | ||
def extra_backend_context(self): | ||
context = super().extra_backend_context() | ||
context["priority_flag"] = self.fields.get( | ||
"priority_flag", MTMessage.PriorityFlag.LEVEL_2.value | ||
) | ||
return context | ||
|
||
|
||
class PriorityBlockingRouter(BlockingRouter): | ||
def new_incoming_message(self, text, connections, class_=IncomingMessage, **kwargs): | ||
return super().new_incoming_message( | ||
text, connections, class_=PriorityIncomingMessage, **kwargs | ||
) | ||
|
||
def new_outgoing_message(self, text, connections, class_=OutgoingMessage, **kwargs): | ||
return super().new_incoming_message( | ||
text, connections, class_=PriorityOutgoingMessage, **kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.