I've further noticed that we could introduce a slight improvement to make middlewares follow the "onion" execution order. For example, if a message is wrapped with pre_send of multiple middlewares, it's generally better to run post_send in reversed order.
I've then inverted the order of post_execute, shutdown, on_error, and post_save so that all existing middleware hooks have an onion-ish invoke order.
A practical use case is that some of my middlewares do modifications to add a mark in pre_send and remove it in post_send. However, without this improvement I couldn't make the mark invisible to other middlewares.
Hi,
I've further noticed that we could introduce a slight improvement to make middlewares follow the "onion" execution order. For example, if a
message
is wrapped withpre_send
of multiple middlewares, it's generally better to runpost_send
in reversed order.I've then inverted the order of
post_execute
,shutdown
,on_error
, andpost_save
so that all existing middleware hooks have an onion-ish invoke order.A practical use case is that some of my middlewares do modifications to add a mark in
pre_send
and remove it inpost_send
. However, without this improvement I couldn't make the mark invisible to other middlewares.The unit tests I added could fail because of other issues: https://github.com/taskiq-python/taskiq/pull/358 and https://github.com/taskiq-python/taskiq/pull/357
As always, let me know if you have suggestions or concerns, and thanks for the review in advance!