Class: Greenroom::Census::Middleware
- Inherits:
-
Object
- Object
- Greenroom::Census::Middleware
- Defined in:
- lib/greenroom/census/middleware.rb
Overview
A Sidekiq server middleware that closes the one gap Census::Job
cannot close on its own: when each_iteration raises, Sidekiq
re-raises out of perform without calling on_stop, so the
thread-local recorder build_enumerator installed is never
uninstalled. Sidekiq reuses worker threads across jobs, so without
this middleware, the next unrelated job Sidekiq happens to run on that
thread would find an experiment already turned on -- the one safety
property this gem promises (a candidate runs only inside a census)
would be broken by an ordinary job failure.
Census::Job#build_enumerator also uninstalls at its own start, as a
second, narrower guard between one census job and the next -- but that
only covers census jobs calling each other; it cannot help an
unrelated job. A host must add this middleware to its Sidekiq server
middleware chain for the guarantee to hold in general.