Commit bb478db0 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Use Sidekiq.dump_json for serializing arguments

This will serialize the arguments into JSON, just like Sidekiq would
for calculating the `#idempotency_string` and checking for duplicate
jobs.

This would be a more robust approach, because serialization of for
example symbols would currently be different when serialized on the
clientside versus after they have been loaded from redis.

It would not have affected anything on a running instance, because the
key is already serialized into the job hash and checked like that in
Sidekiq server.
parent f363da8a
......@@ -133,11 +133,7 @@ module Gitlab
end
def idempotency_string
# TODO: dump the argument's JSON using `Sidekiq.dump_json` instead
# this should be done in the next release so all jobs are written
# with their idempotency key.
# see https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/1090
"#{worker_class_name}:#{arguments.join('-')}"
"#{worker_class_name}:#{Sidekiq.dump_json(arguments)}"
end
end
end
......
......@@ -13,7 +13,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob, :clean_gi
let(:queue) { 'authorized_projects' }
let(:idempotency_key) do
hash = Digest::SHA256.hexdigest("#{job['class']}:#{job['args'].join('-')}")
hash = Digest::SHA256.hexdigest("#{job['class']}:#{Sidekiq.dump_json(job['args'])}")
"#{Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE}:duplicate:#{queue}:#{hash}"
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment