summaryrefslogtreecommitdiff
path: root/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb')
-rw-r--r--lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb b/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb
index 79ac853ea0c..4cf540ce3b8 100644
--- a/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb
+++ b/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb
@@ -19,6 +19,7 @@ module Gitlab
class DuplicateJob
DUPLICATE_KEY_TTL = 6.hours
DEFAULT_STRATEGY = :until_executing
+ STRATEGY_NONE = :none
attr_reader :existing_jid
@@ -51,6 +52,8 @@ module Gitlab
end
end
+ job['idempotency_key'] = idempotency_key
+
self.existing_jid = read_jid.value
end
@@ -100,6 +103,7 @@ module Gitlab
def strategy
return DEFAULT_STRATEGY unless worker_klass
return DEFAULT_STRATEGY unless worker_klass.respond_to?(:idempotent?)
+ return STRATEGY_NONE unless worker_klass.deduplication_enabled?
worker_klass.get_deduplicate_strategy
end
@@ -117,7 +121,7 @@ module Gitlab
end
def idempotency_key
- @idempotency_key ||= "#{namespace}:#{idempotency_hash}"
+ @idempotency_key ||= job['idempotency_key'] || "#{namespace}:#{idempotency_hash}"
end
def idempotency_hash
@@ -129,6 +133,10 @@ 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('-')}"
end
end