summaryrefslogtreecommitdiff
path: root/lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing.rb
blob: 1f7e3a4ea3069e0d19a22fc93a1aea53bb8145ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Gitlab
  module SidekiqMiddleware
    module DuplicateJobs
      module Strategies
        # This strategy takes a lock before scheduling the job in a queue and
        # removes the lock before the job starts allowing a new job to be queued
        # while a job is still executing.
        class UntilExecuting < Base
          extend ::Gitlab::Utils::Override

          include DeduplicatesWhenScheduling

          override :perform
          def perform(job)
            super
            duplicate_job.delete!

            yield
          end
        end
      end
    end
  end
end