Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of middleware execution #446

Open
vovayartsev opened this issue Jul 21, 2021 · 1 comment
Open

Order of middleware execution #446

vovayartsev opened this issue Jul 21, 2021 · 1 comment

Comments

@vovayartsev
Copy link
Contributor

Tested this in exq v0.15.0:

config :exq,
  middleware: [
    Exq.Middleware.Stats,
    Exq.Middleware.Job,
    Exq.Middleware.Manager,
    MyApp.One,
    MyApp.Two
  ]

It appeared that the order of execution of these middleware modules in the success scenario was:

before_work: ONE
before_work: TWO
    <worker module's perform>
after_processed_work: ONE
after_processed_work: TWO

and similar for after_failed_work callbacks in the worker's crash scenario.

Expected behaviour

I thought that after_*_work functions should be called in a reversed order so that middleware modules "wrap" each other like this:

before_work: ONE
  before_work: TWO
    <worker module's perform>
  after_processed_work: TWO
after_processed_work: ONE

This way after_*_work callback of a middleware has a chance to cleanup any side-effects it introduced in before_work (e.g. I'm hacking on pipeline.assigns.worker_module and pipeline.assigns.job.args).

@ananthakumaran
Copy link
Collaborator

At this point, it would be hard to change the existing behavior without breaking some existing code. We could probably consider a compile-time flag if there are some good use cases that can't work based on the current ordering logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants