Class: Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::DeduplicatesWhenScheduling

Inherits:
Base
  • Object
show all
Extended by:
Utils::Override
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/deduplicates_when_scheduling.rb

Direct Known Subclasses

UntilExecuted, UntilExecuting

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(duplicate_job) ⇒ DeduplicatesWhenScheduling

Returns a new instance of DeduplicatesWhenScheduling.


12
13
14
# File 'lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/deduplicates_when_scheduling.rb', line 12

def initialize(duplicate_job)
  @duplicate_job = duplicate_job
end

Instance Method Details

#perform(job) ⇒ Object


35
36
37
# File 'lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/deduplicates_when_scheduling.rb', line 35

def perform(job)
  update_job_wal_location!(job)
end

#schedule(job) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/deduplicates_when_scheduling.rb', line 17

def schedule(job)
  if deduplicatable_job? && check! && duplicate_job.duplicate?
    job['duplicate-of'] = duplicate_job.existing_jid

    if duplicate_job.idempotent?
      duplicate_job.update_latest_wal_location!
      duplicate_job.set_deduplicated_flag!(expiry)

      Gitlab::SidekiqLogging::DeduplicationLogger.instance.deduplicated_log(
        job, "dropped #{strategy_name}", duplicate_job.options)
      return false
    end
  end

  yield
end