Skip to content

Commit

Permalink
Maximum outbound message retry
Browse files Browse the repository at this point in the history
Maximum outbound message deliver retry is switched to parametric. Default value was set as 4 and if --max-outbound-retry parameter is provided as an argument its value is set with this argument value.

Signed-off-by: Özgür Deniz Günseli <[email protected]>
  • Loading branch information
denizgunseli committed May 11, 2020
1 parent 3908936 commit e8c3329
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ def add_arguments(self, parser: ArgumentParser):
to hold messages for delivery to agents without an endpoint. This\
option will require additional memory to store messages in the queue.",
)
parser.add_argument(
"--max-outbound-retry",
default=4,
type=ByteSize(min_size=1),
help="Set the maximum retry number for undelivered outbound\
messages. Increasing this number might cause to increase the\
accumulated messages in message queue. Default value is 4.",
)

def get_settings(self, args: Namespace):
"""Extract transport settings."""
Expand All @@ -712,6 +720,8 @@ def get_settings(self, args: Namespace):
settings["default_label"] = args.label
if args.max_message_size:
settings["transport.max_message_size"] = args.max_message_size
if args.max_outbound_retry:
settings["transport.max_outbound_retry"] = args.max_outbound_retry

return settings

Expand Down
3 changes: 3 additions & 0 deletions aries_cloudagent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ async def test_transport_settings(self):
"80",
"--outbound-transport",
"http",
"--max-outbound-retry",
"5",
]
)

Expand All @@ -50,6 +52,7 @@ async def test_transport_settings(self):

assert settings.get("transport.inbound_configs") == [["http", "0.0.0.0", "80"]]
assert settings.get("transport.outbound_configs") == ["http"]
assert result.max_outbound_retry == 5

def test_bytesize(self):
bs = ByteSize()
Expand Down
6 changes: 5 additions & 1 deletion aries_cloudagent/transport/outbound/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(
class OutboundTransportManager:
"""Outbound transport manager class."""

MAX_RETRY_COUNT = 4

def __init__(
self, context: InjectionContext, handle_not_delivered: Callable = None
):
Expand All @@ -85,6 +87,8 @@ def __init__(
self.running_transports = {}
self.task_queue = TaskQueue(max_active=200)
self._process_task: asyncio.Task = None
if self.context.settings.get("transport.max_outbound_retry"):
self.MAX_RETRY_COUNT = self.context.settings["transport.max_outbound_retry"]

async def setup(self):
"""Perform setup operations."""
Expand Down Expand Up @@ -249,7 +253,7 @@ def enqueue_message(self, context: InjectionContext, outbound: OutboundMessage):
raise OutboundDeliveryError("No supported transport for outbound message")

queued = QueuedOutboundMessage(context, outbound, target, transport_id)
queued.retries = 4
queued.retries = self.MAX_RETRY_COUNT
self.outbound_new.append(queued)
self.process_queued()

Expand Down
8 changes: 8 additions & 0 deletions aries_cloudagent/transport/outbound/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ def test_register_path(self):
mgr = OutboundTransportManager(InjectionContext())
mgr.register("http")
assert mgr.get_registered_transport_for_scheme("http")
assert mgr.MAX_RETRY_COUNT == 4

with self.assertRaises(OutboundTransportRegistrationError):
mgr.register("http")

def test_maximum_retry_count(self):
context = InjectionContext()
context.update_settings({"transport.max_outbound_retry": 5})
mgr = OutboundTransportManager(context)
mgr.register("http")
assert mgr.MAX_RETRY_COUNT == 5

async def test_setup(self):
context = InjectionContext()
context.update_settings({"transport.outbound_configs": ["http"]})
Expand Down

0 comments on commit e8c3329

Please sign in to comment.