require 'redlock'

module ActiveJob
  module Locking
    module Adapters
      class Redlock < Base
        def create_lock_manager
          mapped_options = self.options.adapter_options
          mapped_options[:retry_count] = 2 # Try to get the lock and then try again when timeout is expiring--
          mapped_options[:retry_delay] = self.options.lock_acquire_time * 1000 # convert from seconds to milliseconds

          ::Redlock::Client.new(self.options.hosts, mapped_options)
        end

        def lock
          self.lock_token = self.lock_manager.lock(self.key, self.options.lock_time * 1000)
        end

        def unlock
          self.lock_manager.unlock(self.lock_token)
          self.lock_token = nil
        end
      end
    end
  end
end

require 'redlock'

module ActiveJob
  module Locking
    module Adapters
      class Redlock < Base
        def create_lock_manager
          mapped_options = self.options.adapter_options
          mapped_options[:retry_count] = 2 # Try to get the lock and then try again when timeout is expiring--
          mapped_options[:retry_delay] = self.options.lock_acquire_time * 1000 # convert from seconds to milliseconds

          ::Redlock::Client.new(self.options.hosts, mapped_options)
        end

        def lock
          self.lock_token = self.lock_manager.lock(self.key, self.options.lock_time * 1000)
        end

        def unlock
          self.lock_manager.unlock(self.lock_token.symbolize_keys)
          self.lock_token = nil
        end
      end
    end
  end
end

Fix unlock for Redlock adapter
Fix unlock for Redlock adapter

When lock is deserialized, it is hash containing strings as keys.
Though, Redlock expects lock to have Symbols as keys.
Hence, the job is completed without releasing a lock.

This might be valid for other adapters. (I have not checked it)
If so, the problem must be fixed on `desecialize` step.

Did not find how to set up test environment, so don't have specs,
unfortunately.
