Add deduplication for JSON payloads in job queue

This commit is contained in:
Eugen Rochko 2022-10-25 01:07:00 +02:00
parent 30453fab80
commit 1bfbfb0317
8 changed files with 163 additions and 2 deletions

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
module ArgumentDeduplication
class Client
include Sidekiq::ClientMiddleware
def call(_worker, job, _queue, _redis_pool)
process_arguments!(job)
yield
end
private
def process_arguments!(job)
return unless job['deduplicate_arguments']
argument_index = job['deduplicate_arguments']
argument = Argument.from_value(job['args'][argument_index])
argument.push!
job['args'][argument_index] = argument.content_hash
end
end
end