Skip to content

Commit

Permalink
Increase timeout and disable Postgres notify on send
Browse files Browse the repository at this point in the history
Co-authored-by: Colin Copeland <copelco@caktusgroup.com>
  • Loading branch information
tobiasmcnulty and copelco committed Nov 15, 2024
1 parent f82f05c commit 4f55864
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/smpp_gateway/management/commands/smpp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def add_arguments(self, parser):
type=int,
default=os.environ.get("SMPPLIB_MT_MESSAGES_PER_SECOND", 20),
)
parser.add_argument(
"--socket-timeout",
type=int,
default=os.environ.get("SMPPLIB_SOCKET_TIMEOUT", 30),
)
parser.add_argument(
"--database-url",
default=os.environ.get("DATABASE_URL"),
Expand Down
7 changes: 4 additions & 3 deletions src/smpp_gateway/outgoing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from django.db import connection
# from django.db import connection
from django.utils import timezone
from rapidsms.backends.base import BackendBase

Expand Down Expand Up @@ -48,5 +48,6 @@ def send(self, id_, text, identities, context=None):
MTMessage.objects.bulk_create(
[MTMessage(**kwargs) for kwargs in kwargs_group]
)
with connection.cursor() as curs:
curs.execute(f"NOTIFY {self.model.name}")
# FIXME: Re-enable when we have a way to avoid notifies on bulk SMS
# with connection.cursor() as curs:
# curs.execute(f"NOTIFY {self.model.name}")
4 changes: 4 additions & 0 deletions src/smpp_gateway/smpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get_smpplib_client(
submit_sm_params: dict,
set_priority_flag: bool,
mt_messages_per_second: int,
socket_timeout: int,
hc_check_uuid: str,
hc_ping_key: str,
hc_check_slug: str,
Expand All @@ -38,10 +39,12 @@ def get_smpplib_client(
submit_sm_params,
set_priority_flag,
mt_messages_per_second,
# Pass-through arguments to smpplib.client.Client:
host,
port,
allow_unknown_opt_params=True,
sequence_generator=sequence_generator,
timeout=socket_timeout,
)
return client

Expand Down Expand Up @@ -73,6 +76,7 @@ def start_smpp_client(options):
json.loads(options["submit_sm_params"]),
options["set_priority_flag"],
options["mt_messages_per_second"],
options["socket_timeout"],
options["hc_check_uuid"],
options["hc_ping_key"],
options["hc_check_slug"],
Expand Down
5 changes: 5 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_received_mo_message(self):
{}, # submit_sm_params
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -63,6 +64,7 @@ def test_received_message_receipt(self):
{}, # submit_sm_params
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -106,6 +108,7 @@ def test_received_null_short_message(self):
{}, # submit_sm_params
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -145,6 +148,7 @@ def test_message_sent_handler():
{}, # submit_sm_params
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -183,6 +187,7 @@ def get_client_and_message(
submit_sm_params or {},
set_priority_flag,
20, # mt_messages_per_second
30, # socket_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down

0 comments on commit 4f55864

Please sign in to comment.