summaryrefslogtreecommitdiff
path: root/app/workers/users/deactivate_dormant_users_worker.rb
blob: d024109e754b4d207efec1b06f93030ef1fcbdaa (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
# frozen_string_literal: true

module Users
  class DeactivateDormantUsersWorker # rubocop:disable Scalability/IdempotentWorker
    include ApplicationWorker

    data_consistency :always

    include CronjobQueue

    feature_category :seat_cost_management

    def perform
      return if Gitlab.com?

      return unless ::Gitlab::CurrentSettings.current_application_settings.deactivate_dormant_users

      deactivate_users(User.dormant)
      deactivate_users(User.with_no_activity)
    end

    private

    def deactivate_users(scope)
      with_context(caller_id: self.class.name.to_s) do
        scope.each_batch do |batch|
          batch.each(&:deactivate)
        end
      end
    end
  end
end