2020-03-26 05:07:52 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UpdateHighestRoleWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2022-10-20 05:10:20 -04:00
|
|
|
feature_category :subscription_usage_reports
|
2020-03-26 05:07:52 -04:00
|
|
|
urgency :high
|
|
|
|
weight 2
|
|
|
|
|
|
|
|
idempotent!
|
|
|
|
|
|
|
|
def perform(user_id)
|
2021-11-10 10:13:21 -05:00
|
|
|
user = User.find_by_id(user_id)
|
2020-03-26 05:07:52 -04:00
|
|
|
|
2020-04-01 11:07:45 -04:00
|
|
|
return unless user.present?
|
|
|
|
|
2021-05-11 14:10:36 -04:00
|
|
|
if user.active? && user.human? && !user.internal?
|
2020-04-01 11:07:45 -04:00
|
|
|
Users::UpdateHighestMemberRoleService.new(user).execute
|
|
|
|
else
|
2021-11-10 10:13:21 -05:00
|
|
|
UserHighestRole.where(user_id: user_id).delete_all # rubocop: disable CodeReuse/ActiveRecord
|
2020-04-01 11:07:45 -04:00
|
|
|
end
|
2020-03-26 05:07:52 -04:00
|
|
|
end
|
|
|
|
end
|