diff options
Diffstat (limited to 'app/services/members')
-rw-r--r-- | app/services/members/update_highest_role_service.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/services/members/update_highest_role_service.rb b/app/services/members/update_highest_role_service.rb new file mode 100644 index 00000000000..ce1707c13ec --- /dev/null +++ b/app/services/members/update_highest_role_service.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Members + class UpdateHighestRoleService < ::BaseService + include ExclusiveLeaseGuard + + LEASE_TIMEOUT = 30.minutes.to_i + + attr_reader :user_id + + def initialize(user_id) + @user_id = user_id + end + + def execute + try_obtain_lease do + UpdateHighestRoleWorker.perform_async(user_id) + end + end + + private + + def lease_key + "update_highest_role:#{user_id}" + end + + def lease_timeout + LEASE_TIMEOUT + end + + # Do not release the lease before the timeout to + # prevent multiple jobs being executed during the + # defined timeout + def lease_release? + false + end + end +end |