Skip to content

Commit

Permalink
transport.outbound.manager: remove redundant obj from webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Lee <[email protected]>
  • Loading branch information
victorlee0505 committed Sep 13, 2022
1 parent 85a24ac commit 34c9805
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions aries_cloudagent/transport/outbound/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from typing import Callable, Type, Union
from urllib.parse import urlparse
from collections import MutableMapping
from contextlib import suppress

from ...connections.models.connection_target import ConnectionTarget
from ...core.profile import Profile
Expand All @@ -25,6 +27,8 @@
)
from .message import OutboundMessage

from .constants import ( REMOVE_KEY )

LOGGER = logging.getLogger(__name__)
MODULE_BASE_PATH = "aries_cloudagent.transport.outbound"

Expand Down Expand Up @@ -87,10 +91,13 @@ def __init__(self, profile: Profile, handle_not_delivered: Callable = None):
self.running_transports = {}
self.task_queue = TaskQueue(max_active=200)
self._process_task: asyncio.Task = None
self.light_webhook = False
if self.root_profile.settings.get("transport.max_outbound_retry"):
self.MAX_RETRY_COUNT = self.root_profile.settings[
"transport.max_outbound_retry"
]
if self.root_profile.settings.get("transport.light_weight_webhook"):
self.light_webhook = True

async def setup(self):
"""Perform setup operations."""
Expand Down Expand Up @@ -309,6 +316,14 @@ async def encode_outbound_message(

return outbound_message

def delete_keys_from_dict(self, dictionary, keys):
for key in keys:
with suppress(KeyError):
del dictionary[key]
for value in dictionary.values():
if isinstance(value, MutableMapping):
self.delete_keys_from_dict(value, keys)

def enqueue_webhook(
self,
topic: str,
Expand Down Expand Up @@ -343,6 +358,10 @@ def enqueue_webhook(
queued.payload = json.dumps(payload)
queued.state = QueuedOutboundMessage.STATE_PENDING
queued.retries = 4 if max_attempts is None else max_attempts - 1

if self.light_webhook:
self.delete_keys_from_dict(payload, REMOVE_KEY)
queued.payload = json.dumps(payload)
self.outbound_new.append(queued)
self.process_queued()

Expand Down

0 comments on commit 34c9805

Please sign in to comment.