taskiq icon indicating copy to clipboard operation
taskiq copied to clipboard

Invert execution orders of post, on_error and shutdown middleware hooks

Open hawang-wish opened this issue 1 year ago • 1 comments

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 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.

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!

hawang-wish avatar Aug 29 '24 07:08 hawang-wish

Please fix lints and tests before the review.

s3rius avatar Nov 06 '24 16:11 s3rius