diff options
Diffstat (limited to 'app/models/event.rb')
-rw-r--r-- | app/models/event.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index b6e8bef3f67..55a76e26f3c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -330,13 +330,23 @@ class Event < ActiveRecord::Base # Don't even bother obtaining a lock if the last update happened less than # 60 minutes ago. - return if project.last_activity_at > RESET_PROJECT_ACTIVITY_INTERVAL.ago + return if recent_update? - return unless Gitlab::ExclusiveLease. + return unless try_obtain_lease + + project.update_column(:last_activity_at, created_at) + end + + private + + def recent_update? + project.last_activity_at > RESET_PROJECT_ACTIVITY_INTERVAL.ago + end + + def try_obtain_lease + Gitlab::ExclusiveLease. new("project:update_last_activity_at:#{project.id}", timeout: RESET_PROJECT_ACTIVITY_INTERVAL.to_i). try_obtain - - project.update_column(:last_activity_at, created_at) end end |