summaryrefslogtreecommitdiff
path: root/app/models/event.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-09-19 19:59:29 -0700
committerStan Hu <stanhu@gmail.com>2016-09-19 22:59:15 -0700
commitcf9ee8fda7dbb42f388f0044b22bd3ff2b30048c (patch)
treee2c77195215fb91c974633d6046921852aba7f2b /app/models/event.rb
parentb94de5fd555213ae28030c33c27440228f8efb65 (diff)
downloadgitlab-ce-cf9ee8fda7dbb42f388f0044b22bd3ff2b30048c.tar.gz
Fix broken spec due to last_activity_at updates being throttled
In https://gitlab.com/gitlab-org/gitlab-ce/builds/4218398, the build failed because the last_activity_at column was only being updated once per hour. We can fix this spec by stubbing out the throttling and adjusting the spec to test the right event timestamp.
Diffstat (limited to 'app/models/event.rb')
-rw-r--r--app/models/event.rb18
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