Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Conversation

@mvilanova
Copy link
Contributor

@mvilanova mvilanova commented Nov 22, 2024

Summary of Changes in plugin.py

Imports

  • Added imports for base64 and zlib.
  • Reordered imports for better organization.

New Function

  • Added a new function decompress_json to handle decompression of base64 encoded zlibbed JSON strings.
def decompress_json(compressed_str: str) -> str:
    """Decompress a base64 encoded zlibbed JSON string."""
    decoded = base64.b64decode(compressed_str)
    decompressed = zlib.decompress(decoded)
    return decompressed.decode("utf-8")

Class AWSSQSSignalConsumerPlugin

  • Updated the description attribute for better readability.
  • Added logic to handle decompression of messages if they are marked as compressed with zlib.
  • Improved logging messages for better clarity and consistency.

Detailed Changes

  • Description Update: Changed description from "Uses sqs to consume signals" to "Uses SQS to consume signals."
  • Message Handling: Added logic to check for a compressed attribute in MessageAttributes and decompress the message body if necessary.
  • Logging Improvements: Enhanced log messages to be more descriptive and consistent.
if message_attributes.get("compressed", {}).get("StringValue") == "zlib":
    # Message is compressed, decompress it
    message_body = decompress_json(message_body)
  • Error Handling: Improved error messages for ValidationError, IntegrityError, and general exceptions to provide more context.
log.warning(
    f"Received a signal instance that does not conform to the `SignalInstanceCreate` structure. Skipping creation: {e}"
)
log.info(
    f"Received a signal instance that already exists in the database. Skipping creation: {signal_instance_in.raw['id']}"
)
log.exception(
    f"Encountered an Integrity error when trying to create a signal instance: {e}"
)
log.exception(f"Unable to create signal instance: {e}")
  • Signal Logging: Updated log message for received signals to include both the signal name and ID.
log.debug(
    f"Received a signal with name {signal_instance.signal.name} and id {signal_instance.signal.id}"
)

These changes enhance the functionality of the AWSSQSSignalConsumerPlugin by adding support for compressed messages and improving the clarity and consistency of log messages.

@mvilanova mvilanova added the enhancement New feature or request label Nov 22, 2024
@mvilanova mvilanova changed the title feat(dispatch aws plugin): adds support for decompressing signals feat(dispatch aws plugin): adds support for decompressing zlib compressed signals Dec 5, 2024
@mvilanova mvilanova merged commit a8b57b6 into master Dec 9, 2024
8 checks passed
@mvilanova mvilanova deleted the feat/dispatch_aws-decompress branch December 9, 2024 20:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants