diff --git a/src/smpp_gateway/client.py b/src/smpp_gateway/client.py index ed5d1d2..8dc3e2a 100644 --- a/src/smpp_gateway/client.py +++ b/src/smpp_gateway/client.py @@ -69,6 +69,7 @@ def __init__( backend: Backend, hc_worker: HealthchecksIoWorker, submit_sm_params: dict, + mt_messages_per_second: int, *args, **kwargs, ): @@ -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) @@ -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"]} @@ -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 @@ -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: diff --git a/src/smpp_gateway/management/commands/smpp_client.py b/src/smpp_gateway/management/commands/smpp_client.py index 00c2cfb..e484f69 100644 --- a/src/smpp_gateway/management/commands/smpp_client.py +++ b/src/smpp_gateway/management/commands/smpp_client.py @@ -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"), diff --git a/src/smpp_gateway/smpp.py b/src/smpp_gateway/smpp.py index 5821f9f..44ff4e2 100644 --- a/src/smpp_gateway/smpp.py +++ b/src/smpp_gateway/smpp.py @@ -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, @@ -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, @@ -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"], diff --git a/tests/test_client.py b/tests/test_client.py index 14aaefa..280ce09 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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 @@ -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 @@ -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 @@ -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