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

deactivate_dormant_users_worker.rb « users « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33c54f07521b64fc0ed33f7f54a48f8d93bc047c (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
35
36
37
# 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

      admin_bot = Users::Internal.admin_bot
      return unless admin_bot

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

    private

    def deactivate_users(scope, admin_bot)
      with_context(caller_id: self.class.name.to_s) do
        scope.each_batch do |batch|
          batch.each do |user|
            Users::DeactivateService.new(admin_bot).execute(user)
          end
        end
      end
    end
  end
end