# frozen_string_literal: true module Wayfarer module Middleware class Dedup extend Base include Wayfarer::Logging.emit( deduplicated: [:info, "Deduplicated URL"], retry: [:debug, "Not deduplicating retry"], rerouted: [:debug, "Not deduplicating rerouted task"] ) def call(task) task[:barrier] ||= Wayfarer::Redis::Barrier.new(task) if task[:job].executions > 1 log(:retry, task) return yield if block_given? end if task[:job] != task[:controller] log(:rerouted, task) return yield if block_given? end return log(:deduplicated, task) if task[:barrier].check!(task[:normalized_url]) yield if block_given? end end end end