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

Increase timeout and disable Postgres notify on send #27

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/smpp_gateway/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(
submit_sm_params: dict,
set_priority_flag: bool,
mt_messages_per_second: int,
event_loop_timeout: int,
*args,
**kwargs,
):
Expand All @@ -81,6 +82,7 @@ def __init__(
self.submit_sm_params = submit_sm_params
self.set_priority_flag = set_priority_flag
self.mt_messages_per_second = mt_messages_per_second
self.event_loop_timeout = event_loop_timeout
super().__init__(*args, **kwargs)
self._pg_conn = pg_listen(self.backend.name)

Expand Down Expand Up @@ -176,11 +178,13 @@ def receive_pg_notify(self):
self.send_mt_messages()

def send_mt_messages(self):
limit = self.mt_messages_per_second * self.timeout
limit = self.mt_messages_per_second * self.event_loop_timeout
smses = get_mt_messages_to_send(limit=limit, backend=self.backend)
if len(smses) == 0:
return
logger.info(f"Found {len(smses)} messages to send in {self.timeout} seconds")
logger.info(
f"Found {len(smses)} messages to send in {self.event_loop_timeout} seconds"
)
submit_sm_resps = []
for sms in smses:
params = {**self.submit_sm_params, **sms["params"]}
Expand Down Expand Up @@ -237,7 +241,7 @@ def listen(self, ignore_error_codes=None, auto_send_enquire_link=True):
while True:
# When either main socket has data or _pg_conn has data, select.select will return
rlist, _, _ = select.select(
[self._socket, self._pg_conn], [], [], self.timeout
[self._socket, self._pg_conn], [], [], self.event_loop_timeout
)
if not rlist and auto_send_enquire_link:
self.logger.debug("Socket timeout, listening again")
Expand Down
9 changes: 8 additions & 1 deletion src/smpp_gateway/management/commands/smpp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ def add_arguments(self, parser):
parser.add_argument(
"--socket-timeout",
type=int,
default=os.environ.get("SMPPLIB_SOCKET_TIMEOUT", 5),
default=os.environ.get("SMPPLIB_SOCKET_TIMEOUT", 30),
)
parser.add_argument(
"--event-loop-timeout",
type=int,
default=os.environ.get("SMPPLIB_EVENT_LOOP_TIMEOUT", 5),
help="Timeout for listening for Postgres notifications and new "
"incoming messages.",
simonkagwi marked this conversation as resolved.
Show resolved Hide resolved
)
parser.add_argument(
"--database-url",
Expand Down
3 changes: 3 additions & 0 deletions src/smpp_gateway/smpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_smpplib_client(
set_priority_flag: bool,
mt_messages_per_second: int,
socket_timeout: int,
event_loop_timeout: int,
hc_check_uuid: str,
hc_ping_key: str,
hc_check_slug: str,
Expand All @@ -39,6 +40,7 @@ def get_smpplib_client(
submit_sm_params,
set_priority_flag,
mt_messages_per_second,
event_loop_timeout,
# Pass-through arguments to smpplib.client.Client:
host,
port,
Expand Down Expand Up @@ -77,6 +79,7 @@ def start_smpp_client(options):
options["set_priority_flag"],
options["mt_messages_per_second"],
options["socket_timeout"],
options["event_loop_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 @@ -27,6 +27,7 @@ def test_received_mo_message(self):
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
5, # event_loop_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -65,6 +66,7 @@ def test_received_message_receipt(self):
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
5, # event_loop_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -109,6 +111,7 @@ def test_received_null_short_message(self):
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
5, # event_loop_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -149,6 +152,7 @@ def test_message_sent_handler():
False, # set_priority_flag
20, # mt_messages_per_second
30, # socket_timeout
5, # event_loop_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -188,6 +192,7 @@ def get_client_and_message(
set_priority_flag,
20, # mt_messages_per_second
30, # socket_timeout
5, # event_loop_timeout
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down
Loading