Class: PersonalAccessTokens::LastUsedService
- Inherits:
-
Object
- Object
- PersonalAccessTokens::LastUsedService
- Includes:
- ExclusiveLeaseGuard, Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/personal_access_tokens/last_used_service.rb
Constant Summary collapse
- LEASE_TIMEOUT =
60.seconds.to_i
- LAST_USED_IP_TIMEOUT =
1.minute
- LAST_USED_AT_TIMEOUT =
10.minutes
- NUM_IPS_TO_STORE =
5
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(personal_access_token) ⇒ LastUsedService
constructor
A new instance of LastUsedService.
Methods included from ExclusiveLeaseGuard
#exclusive_lease, #lease_taken_message, #log_lease_taken, #release_lease, #renew_lease!, #try_obtain_lease
Constructor Details
#initialize(personal_access_token) ⇒ LastUsedService
Returns a new instance of LastUsedService.
13 14 15 |
# File 'app/services/personal_access_tokens/last_used_service.rb', line 13 def initialize(personal_access_token) @personal_access_token = personal_access_token end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/personal_access_tokens/last_used_service.rb', line 17 def execute # Needed to avoid calling service on Oauth tokens return unless @personal_access_token.has_attribute?(:last_used_at) # We _only_ want to update last_used_at and not also updated_at (which # would be updated when using #touch). return unless needs_update? lb = @personal_access_token.load_balancer try_obtain_lease do ::Gitlab::Database::LoadBalancing::SessionMap.current(lb).without_sticky_writes do update_pat_ip if last_used_ip_needs_update? if last_used_at_needs_update? end end end |