diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-20 13:42:46 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-20 13:42:46 +0300 |
commit | 8c41d5f5e13c321aa38d7636e608dc84371cfd5d (patch) | |
tree | 6a68d0a5657015a8ce1a173d8ce9c294b2e40459 /app | |
parent | 5a41d92b9d73cbc41b649239e40a15955094f77e (diff) |
Record used SSH keys only once per day
Use Gitlab::ExclusiveLease to make sure that we enqueue Sidekiq job
at most once per day for given key.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/key.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index 8be29c697f1..9c74ca84753 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -4,6 +4,8 @@ class Key < ActiveRecord::Base include AfterCommitQueue include Sortable + LAST_USED_AT_REFRESH_TIME = 1.day.to_i + belongs_to :user before_validation :generate_fingerprint @@ -50,7 +52,10 @@ class Key < ActiveRecord::Base end def update_last_used_at - UseKeyWorker.perform_async(self.id) + lease = Gitlab::ExclusiveLease.new("key_update_last_used_at:#{id}", timeout: LAST_USED_AT_REFRESH_TIME) + return unless lease.try_obtain + + UseKeyWorker.perform_async(id) end def add_to_shell |