gitlab-org--gitlab-foss/app/workers/remove_expired_members_worker.rb

26 lines
811 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class RemoveExpiredMembersWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
feature_category :authentication_and_authorization
worker_resource_boundary :cpu
# rubocop: disable CodeReuse/ActiveRecord
def perform
Member.expired.preload(:user).find_each do |member|
2019-03-13 09:42:43 -04:00
Members::DestroyService.new.execute(member, skip_authorization: true)
expired_user = member.user
if expired_user.project_bot?
Users::DestroyService.new(nil).execute(expired_user, skip_authorization: true)
end
2019-03-13 09:42:43 -04:00
rescue => ex
logger.error("Expired Member ID=#{member.id} cannot be removed - #{ex}")
end
end
# rubocop: enable CodeReuse/ActiveRecord
end