1
0
Fork 0
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:
Eugene Kenny 2020-08-25 17:26:42 +01:00 committed by GitHub
parent bc0e2fb414
commit d9cc977f1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View file

@ -6,6 +6,7 @@ HEAD
---------
- Fix Web UI crash with corrupt session [#4672]
- Allow middleware to yield arguments [#4673, @eugeneius]
6.1.1
---------

View file

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

View file

@ -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'