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

Allow MT message send rate to be configured #22

Merged
merged 1 commit into from
Nov 14, 2024
Merged
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
11 changes: 8 additions & 3 deletions src/smpp_gateway/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
backend: Backend,
hc_worker: HealthchecksIoWorker,
submit_sm_params: dict,
mt_messages_per_second: int,
*args,
**kwargs,
):
Expand All @@ -77,6 +78,7 @@ def __init__(
self.backend = backend
self.hc_worker = hc_worker
self.submit_sm_params = submit_sm_params
self.mt_messages_per_second = mt_messages_per_second
super().__init__(*args, **kwargs)
self._pg_conn = pg_listen(self.backend.name)

Expand Down Expand Up @@ -172,7 +174,11 @@ def receive_pg_notify(self):
self.send_mt_messages()

def send_mt_messages(self):
smses = get_mt_messages_to_send(limit=100, backend=self.backend)
limit = self.mt_messages_per_second * self.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")
submit_sm_resps = []
for sms in smses:
params = {**self.submit_sm_params, **sms["params"]}
Expand Down Expand Up @@ -222,7 +228,7 @@ def split_and_send_message(self, message, **kwargs):

def listen(self, ignore_error_codes=None, auto_send_enquire_link=True):
self.logger.info("Entering main listen loop")
# Look for and send up to 100 messages on start up
# Look for and send messages on start up
self.send_mt_messages()
while True:
# When either main socket has data or _pg_conn has data, select.select will return
Expand All @@ -233,7 +239,6 @@ def listen(self, ignore_error_codes=None, auto_send_enquire_link=True):
self.logger.debug("Socket timeout, listening again")
pdu = smpplib.smpp.make_pdu("enquire_link", client=self)
self.send_pdu(pdu)
# Look for and send up to 100 messages every 5 seconds
self.send_mt_messages()
continue
elif not rlist:
Expand Down
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 @@ -51,6 +51,11 @@ def add_arguments(self, parser):
"--submit-sm-params",
default=os.environ.get("SMPPLIB_SUBMIT_SM_PARAMS", r"{}"),
)
parser.add_argument(
"--mt-messages-per-second",
type=int,
default=os.environ.get("SMPPLIB_MT_MESSAGES_PER_SECOND", 20),
)
parser.add_argument(
"--database-url",
default=os.environ.get("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 @@ -18,6 +18,7 @@ def get_smpplib_client(
notify_mo_channel: str,
backend: Backend,
submit_sm_params: dict,
mt_messages_per_second: int,
hc_check_uuid: str,
hc_ping_key: str,
hc_check_slug: str,
Expand All @@ -34,6 +35,7 @@ def get_smpplib_client(
backend,
hc_worker,
submit_sm_params,
mt_messages_per_second,
host,
port,
allow_unknown_opt_params=True,
Expand Down Expand Up @@ -67,6 +69,7 @@ def start_smpp_client(options):
options["notify_mo_channel"],
backend,
json.loads(options["submit_sm_params"]),
options["mt_messages_per_second"],
options["hc_check_uuid"],
options["hc_ping_key"],
options["hc_check_slug"],
Expand Down
4 changes: 4 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_received_mo_message(self):
"notify_mo_channel",
backend,
{}, # submit_sm_params
20, # mt_messages_per_second
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -57,6 +58,7 @@ def test_received_message_receipt(self):
"notify_mo_channel",
backend,
{}, # submit_sm_params
20, # mt_messages_per_second
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -98,6 +100,7 @@ def test_received_null_short_message(self):
"notify_mo_channel",
backend,
{}, # submit_sm_params
20, # mt_messages_per_second
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down Expand Up @@ -135,6 +138,7 @@ def test_message_sent_handler():
"notify_mo_channel",
backend,
{}, # submit_sm_params
20, # mt_messages_per_second
"", # hc_check_uuid
"", # hc_ping_key
"", # hc_check_slug
Expand Down
Loading