mhenrixon/sidekiq-unique-jobs

register_reaper_process nx: true crash Sidekiq on startup

jamesst20 opened this issue · 2 comments

Describe the bug
Sidekiq crash on startup

worker | Unsupported command argument type: TrueClass
worker | /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/redis-client-0.18.0/lib/redis_client/command_builder.rb:37:in `block in generate'
worker | /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/redis-client-0.18.0/lib/redis_client/command_builder.rb:28:in `map!'
worker | /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/redis-client-0.18.0/lib/redis_client/command_builder.rb:28:in `generate'
worker | /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/redis-client-0.18.0/lib/redis_client.rb:253:in `call'
worker | /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-7.2.0/lib/sidekiq/redis_client_adapter.rb:36:in `block (2 levels) in <module:CompatMethods>'
worker | /Users/james/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-unique-jobs-8.0.3/lib/sidekiq_unique_jobs/orphans/manager.rb:195:in `block in register_reaper_process'
...

Commenting out this line in the initializer prevent the error:

SidekiqUniqueJobs::Server.configure(config)

Additional context

Rails 7.1
sidekiq-unique-jobs (master) 8.0.4
Sidekiq 7.2.0

From my understanding:

      def register_reaper_process
        redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, nx: true, ex: drift_reaper_interval) }
      end

When register_reaper_process is called, RedisClient::CommandBuilder#generate is called and that method is like such:

def generate(args, kwargs = nil)

     # args = ["set", "uniquejobs:reaper", 1699548261, {:nx=>true, :ex=>612}]

        command = args.flat_map do |element|
          case element
          when Hash
            element.flatten # so here  {:nx=>true, :ex=>612} becomes [:nx, true, :ex, 612]
          else
            element
          end
        end
        ...
        command.map! do |element|
          case element
          when String
            element
          when Symbol
            element.name
          when Integer, Float
            element.to_s
          else
            raise TypeError, "Unsupported command argument type: #{element.class}". <---- Exception is raised Unsupported command argument type: TrueClass. It processes, the true from {nx: true, ...} that was flattened
          end
        end

Thanks everyone! @mhenrixon could we cut a new release for this 🙏🏼