Welcome to mirror list, hosted at ThFree Co, Russian Federation.

disallow_two_factor_for_subgroups_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02dceee2488e7724b4ac6c7c85296548a36754b9 (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
27
28
29
30
31
32
33
34
# frozen_string_literal: true

class DisallowTwoFactorForSubgroupsWorker
  include ApplicationWorker

  data_consistency :always

  sidekiq_options retry: 3
  include ExceptionBacktrace

  INTERVAL = 2.seconds.to_i

  feature_category :groups_and_projects
  idempotent!

  def perform(group_id)
    begin
      group = Group.find(group_id)
    rescue ActiveRecord::RecordNotFound
      return
    end

    # rubocop: disable CodeReuse/ActiveRecord
    subgroups = group.descendants.where(require_two_factor_authentication: true) # rubocop: disable CodeReuse/ActiveRecord
    subgroups.find_each(batch_size: 100).with_index do |subgroup, index|
      delay = index * INTERVAL

      with_context(namespace: subgroup) do
        DisallowTwoFactorForGroupWorker.perform_in(delay, subgroup.id)
      end
    end
    # rubocop: enable CodeReuse/ActiveRecord
  end
end