Class: Keys::LastUsedService
- Inherits:
-
Object
- Object
- Keys::LastUsedService
- Defined in:
- app/services/keys/last_used_service.rb
Constant Summary collapse
- TIMEOUT =
1.day
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #execute ⇒ Object
- #execute_async ⇒ Object
-
#initialize(key) ⇒ LastUsedService
constructor
key - The Key for which to update the last used timestamp.
- #update? ⇒ Boolean
Constructor Details
#initialize(key) ⇒ LastUsedService
key - The Key for which to update the last used timestamp.
10 11 12 |
# File 'app/services/keys/last_used_service.rb', line 10 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'app/services/keys/last_used_service.rb', line 7 def key @key end |
Instance Method Details
#execute ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/services/keys/last_used_service.rb', line 14 def execute return unless update? # We _only_ want to update last_used_at and not also updated_at (which # would be updated when using #touch). key.update_column(:last_used_at, Time.zone.now) end |
#execute_async ⇒ Object
22 23 24 25 26 |
# File 'app/services/keys/last_used_service.rb', line 22 def execute_async return unless update? ::SshKeys::UpdateLastUsedAtWorker.perform_async(key.id) end |
#update? ⇒ Boolean
28 29 30 31 32 33 |
# File 'app/services/keys/last_used_service.rb', line 28 def update? return false if ::Gitlab::Database.read_only? last_used = key.last_used_at last_used.blank? || last_used <= TIMEOUT.ago end |