mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Allow middleware to yield arguments (#4673)
The arguments are always ignored, but this allows the block to be passed to a method that yields arguments: class TaggedLoggingMiddleware def call(*, &block) Rails.logger.tagged("my cool job", &block) end end
This commit is contained in:
parent
bc0e2fb414
commit
d9cc977f1a
3 changed files with 17 additions and 1 deletions
|
@ -6,6 +6,7 @@ HEAD
|
|||
---------
|
||||
|
||||
- Fix Web UI crash with corrupt session [#4672]
|
||||
- Allow middleware to yield arguments [#4673, @eugeneius]
|
||||
|
||||
6.1.1
|
||||
---------
|
||||
|
|
|
@ -133,7 +133,7 @@ module Sidekiq
|
|||
return yield if empty?
|
||||
|
||||
chain = retrieve.dup
|
||||
traverse_chain = lambda do
|
||||
traverse_chain = proc do
|
||||
if chain.empty?
|
||||
yield
|
||||
else
|
||||
|
|
|
@ -41,6 +41,12 @@ describe Sidekiq::Middleware do
|
|||
end
|
||||
end
|
||||
|
||||
class ArgumentYieldingMiddleware
|
||||
def call(*args)
|
||||
yield 1
|
||||
end
|
||||
end
|
||||
|
||||
class AnotherCustomMiddleware
|
||||
def initialize(name, recorder)
|
||||
@name = name
|
||||
|
@ -113,6 +119,15 @@ describe Sidekiq::Middleware do
|
|||
assert_equal [], recorder
|
||||
end
|
||||
|
||||
it 'allows middleware to yield arguments' do
|
||||
chain = Sidekiq::Middleware::Chain.new
|
||||
chain.add ArgumentYieldingMiddleware
|
||||
|
||||
final_action = nil
|
||||
chain.invoke { final_action = true }
|
||||
assert_equal true, final_action
|
||||
end
|
||||
|
||||
describe 'I18n' do
|
||||
before do
|
||||
require 'i18n'
|
||||
|
|
Loading…
Reference in a new issue