Class: SimpleMutex::BaseCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_mutex/base_cleaner.rb

Instance Method Summary collapse

Instance Method Details

#unlockObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/simple_mutex/base_cleaner.rb', line 5

def unlock
  ::SimpleMutex.redis_check!

  logger&.info(start_msg)

  redis.keys.select do |lock_key|
    redis.watch(lock_key) do
      raw_data = redis.get(lock_key)

      next redis.unwatch if raw_data.nil?

      parsed_data = safe_parse(raw_data)

      next redis.unwatch unless parsed_data&.dig("payload", "type") == type

      entity_id = parsed_data&.dig(*path_to_entity_id)

      next redis.unwatch if entity_id.nil? || active?(entity_id)

      return_value = redis.multi { redis.del(lock_key) }

      log_iteration(lock_key, raw_data, return_value) unless logger.nil?

      return_value.first.positive?
    end
  end

  logger&.info(end_msg)
end