diff options
Diffstat (limited to 'app/workers/users')
-rw-r--r-- | app/workers/users/create_statistics_worker.rb | 2 | ||||
-rw-r--r-- | app/workers/users/deactivate_dormant_users_worker.rb | 51 | ||||
-rw-r--r-- | app/workers/users/update_open_issue_count_worker.rb | 26 |
3 files changed, 79 insertions, 0 deletions
diff --git a/app/workers/users/create_statistics_worker.rb b/app/workers/users/create_statistics_worker.rb index fb1b192577f..e44039f2016 100644 --- a/app/workers/users/create_statistics_worker.rb +++ b/app/workers/users/create_statistics_worker.rb @@ -3,6 +3,8 @@ module Users class CreateStatisticsWorker # rubocop:disable Scalability/IdempotentWorker include ApplicationWorker + + sidekiq_options retry: 3 # rubocop:disable Scalability/CronWorkerContext # This worker does not perform work scoped to a context include CronjobQueue diff --git a/app/workers/users/deactivate_dormant_users_worker.rb b/app/workers/users/deactivate_dormant_users_worker.rb new file mode 100644 index 00000000000..e583823312f --- /dev/null +++ b/app/workers/users/deactivate_dormant_users_worker.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Users + class DeactivateDormantUsersWorker # rubocop:disable Scalability/IdempotentWorker + include ApplicationWorker + + include CronjobQueue + + feature_category :utilization + tags :exclude_from_kubernetes + + NUMBER_OF_BATCHES = 50 + BATCH_SIZE = 200 + PAUSE_SECONDS = 0.25 + + def perform + return if Gitlab.com? + + return unless ::Gitlab::CurrentSettings.current_application_settings.deactivate_dormant_users + + with_context(caller_id: self.class.name.to_s) do + NUMBER_OF_BATCHES.times do + result = User.connection.execute(update_query) + + break if result.cmd_tuples == 0 + + sleep(PAUSE_SECONDS) + end + end + end + + private + + def update_query + <<~SQL + UPDATE "users" + SET "state" = 'deactivated' + WHERE "users"."id" IN ( + (#{users.dormant.to_sql}) + UNION + (#{users.with_no_activity.to_sql}) + LIMIT #{BATCH_SIZE} + ) + SQL + end + + def users + User.select(:id).limit(BATCH_SIZE) + end + end +end diff --git a/app/workers/users/update_open_issue_count_worker.rb b/app/workers/users/update_open_issue_count_worker.rb new file mode 100644 index 00000000000..d9e313d53df --- /dev/null +++ b/app/workers/users/update_open_issue_count_worker.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Users + class UpdateOpenIssueCountWorker + include ApplicationWorker + + feature_category :users + tags :exclude_from_kubernetes + idempotent! + + def perform(target_user_ids) + target_user_ids = Array.wrap(target_user_ids) + + raise ArgumentError, 'No target user ID provided' if target_user_ids.empty? + + target_users = User.id_in(target_user_ids) + raise ArgumentError, 'No valid target user ID provided' if target_users.empty? + + target_users.each do |user| + Users::UpdateAssignedOpenIssueCountService.new(target_user: user).execute + end + rescue StandardError => exception + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(exception) + end + end +end |