Releases: kalaspuff/tomodachi
0.25.1
-
Fix for an issue where a wrapped function is used as a handler function, which would then cause the keyword argument provided transport values to rely on the keyword arguments from the wrapped function's signature to be used instead of the keyword arguments from the wrapper function's signature. Described with examples in #1781.
The bug was found to be present in the 0.25.0 release, which included major refactoring of the keyword argument provided transport values functionality.
0.25.0
-
The middleware execution logic has been improved to handle different argument types and edge cases more smoothly. Enhanced the way arguments are passed to middlewares and handlers, allowing better flexibility.
-
Function handlers, middlewares and envelopes can all now specify additional keyword arguments in their signatures and receive transport centric values.
Previously a few of these keyword values could be used for function handlers or envelopes, but not within middlewares. With this update these keywords can be used across all kind of handler functions to allow for more flexibility in how to structure apps, logging, tracing, authentication, etc.
-
Resolved an edge case where a service could end up calling
SNS.CreateTopic
numerous times due to thousands of messages simultanously being published to a topic that were previously unknown to the service. Described in the detail in #1768. -
The
aws_sns_sqs_publish
function will now return the SNS message identifier as astr
value if it is called withwait=True
(default), or instead return anasyncio.Task
object if called withwait=False
.
Updated documentation on middlewares and function signature keyword arguments:
- See examples of custom middleware: https://tomodachi.dev/docs/middlewares.
- See the full list of function signature keywords that can be used: https://tomodachi.dev/docs/function-keywords.
This is an example of a middleware function for AWS SNS SQS messaging that adds trace spans on receiving messages, with a context extracted from a message attribute holding with a "traceparent" value. The topic name and SNS message identifier is also added as attributes to the trace span.
async def trace_middleware(
func: Callable[... Awaitable],
*,
topic: str,
message_attributes: dict,
sns_message_id: str
) -> None:
ctx: Context | None = None
if carrier_traceparent := message_attributes.get("telemetry.carrier.traceparent"):
carrier: dict[str, list[str] | str] = {"traceparent": carrier_traceparent}
ctx = TraceContextTextMapPropagator().extract(carrier=carrier)
with tracer.start_as_current_span(f"SNSSQS handler '{func.__name__}'", context=ctx) as span:
span.set_attribute("messaging.system", "AmazonSQS")
span.set_attribute("messaging.operation", "process")
span.set_attribute("messaging.source.name", topic)
span.set_attribute("messaging.message.id", sns_message_id)
try:
# Calls the handler function (or next middleware in the chain)
await func()
except BaseException as exc:
logging.getLogger("exception").exception(exc)
span.record_exception(exc, escaped=True)
span.set_status(StatusCode.ERROR, f"{exc.__class__.__name__}: {exc}")
raise exc
0.24.3
-
Fixes an issue in the internal retry logic when using
aws_sns_sqs_publish
if calls to the AWS APISNS.Publish
would intermittently respond with 408 response without any body, which previously would've resulted in aAWSSNSSQSException("Missing MessageId in response")
immediately without retries.This was previously attempted to be fixed in #1664 (released in 0.23.0), but due to an error it fell through to become an exception with the
"Missing MessageId in response"
message instead.The publish function will now catch exceptions from
botocore
of typeResponseParserError
to whichbotocore
has added that"Further retries may succeed"
.tomodachi
will retry suchSNS.Publish
calls up to 3 times and if still failing after all retries the library will reraise the originalbotocore
exception.It seems that
botocore
does not automatically retry such errors itself. -
Similar to the above, the same kind of retries will now also be done during AWS API calls for
SQS.DeleteMessage
, where thebotocore.parser.QueryParser
would raise anResponseParserError
exception on 408 responses without body.
0.24.2
- Fixes typing syntax for compatibility with Python 3.8 and Python 3.9 to solve the incompatibility for Python 3.8 and Python 3.9 introduced in the the 0.24.1 release.
- Fixes an issue with an AWS SQS queue's message retention period attribute using an incompatible default value for FIFO queues.
- Support for
aiobotocore
2.5.x releases. - README.rst fixes to conform with RST format. (github: @navid-agz)
0.24.1
- Adds max number of messages that the service will consume when using AWS SNS+SQS
handlers configurable. (github: @navid-agz) - Changed default retention period of dead-letter-queues on AWS SNS+SQS.
(github: @PabloAJomer)
0.24.0
cchardet
is no longer a direct dependency totomodachi
on Python 3.10 and Python 3.11. If you want to use it, you must install it separately, which may require additional build tools when installing on Python 3.10+.- Updates to the internal
tomodachi.envelope.ProtobufBase
envelope to now also support protobuf Python bindings versioned >=4.0.0, when running with the (new default)PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=upb
asupb
slightly differs in representation of a Message type in relation tocpp
andpython
implementations. - Python 3.11 added to test matrix and trove classifiers to officially claim support.
0.23.0
-
Properly handles
aiobotocore
client using an async contextmanager. Drops support foraiobotocore
versions prior 1.3.0, but will now supporting newer versions. (github: @drestrepom) -
Fixes an issue to now retry calls where AWS SNS intermittently responds with 408 responses without any body, which trips up
botocore.parser.QueryParser
. (github: @technomunk) -
Refactored options used for AWS SNS+SQS, HTTP, AMQP and the Watcher functionality. Options set on the service class should now be defined as a
tomodachi.Options
object, which provides type hints and much nicer path traversal of the class.Only the specified typed values for
options
will now be allowed to be set. Setting a non-defined option will raise anAttributeError
exception on service start.The previous
dict
based approach is still supported, but will be removed in a future version. -
Dropped support for Python 3.7.
0.22.3
- Support for assigning values to AWS SQS queue attributes value
VisibilityTimeout
andRedrivePolicy
that is used to assign a queue to use a dead-letter queue after a number of failed attempts to consume a message. By default no changes will be done to the existing queue attributes and a change will only be triggered by assigning values to thevisibility_timeout
or both ofdead_letter_queue_name
+max_receive_count
keyword arguments.
@tomodachi.aws_sns_sqs(
topic=None,
competing=True,
queue_name=None,
filter_policy=FILTER_POLICY_DEFAULT,
visibility_timeout=VISIBILITY_TIMEOUT_DEFAULT, # affects MessageVisibility
dead_letter_queue_name=DEAD_LETTER_QUEUE_DEFAULT, # affects RedrivePolicy
max_receive_count=MAX_RECEIVE_COUNT_DEFAULT, # affects RedrivePolicy
**kwargs,
)
- Fixes a bug where SQS messages wouldn't get deleted from the queue if a middleware function catches an exception without reraising it. This is because the
delete_message
is not called from withinroutine_func
(due to the exception breaking normal control flow), but the message deletion from middleware bubble is also skipped, as no exception is propagated from it. (github: @technomunk) - Adds basic support for FIFO queues & topics on AWS SQS queues managed by a
tomodachi
service decorated function, which can be used where one needs guaranteed ordering of the consumed messages. (github: @kjagiello) - Updates to the internal
tomodachi.envelope.ProtobufBase
envelope to now also support newer versions of protobuf. - Added documentation to describe the "magic" functions that hooks into the service lifecycle;
_start_service
,_started_service
,_stopping_service
,_stop_service
.
0.22.2
- Fixes an issue with live reloading on code changes (development mode) with services utilizing
protobuf
messages, which in same edge cases could trigger a repeatedTypeError("A Message class can only inherit from Message")
that would prevent the service from restarting correctly.
0.22.1
- Added an additional way of gracefully triggering shutdown of a running service, by using the new
tomodachi.exit()
function, which will initiate the termination processing flow in the same way as signalingSIGINT
orSIGTERM
. Thetomodachi.exit()
call can additionally take an optional exit code as an argument to support new ways of catching service operation. - The process' exit code can also be altered by changing the value of
tomodachi.SERVICE_EXIT_CODE
, however using the newtomodachi.exit
call with an integer argument will override any previous value set totomodachi.SERVICE_EXIT_CODE
. The default value is set to0
.