Commit 2212dad6 authored by Toon Claes's avatar Toon Claes

Do not check for secondary? but use readonly? instead

See gitlab-org/gitlab-ee!2983.
parent d1164bd7
module Keys module Keys
class LastUsedService class LastUsedService
prepend ::EE::Keys::LastUsedService
TIMEOUT = 1.day.to_i TIMEOUT = 1.day.to_i
attr_reader :key attr_reader :key
...@@ -18,6 +16,8 @@ module Keys ...@@ -18,6 +16,8 @@ module Keys
end end
def update? def update?
return false if ::Gitlab::Database.readonly?
last_used = key.last_used_at last_used = key.last_used_at
return false if last_used && (Time.zone.now - last_used) <= TIMEOUT return false if last_used && (Time.zone.now - last_used) <= TIMEOUT
......
module EE
module Keys
module LastUsedService
def update?
raise NotImplementedError unless defined?(super)
!::Gitlab::Geo.secondary? && super
end
end
end
end
require 'spec_helper' require 'spec_helper'
describe Keys::LastUsedService do describe Keys::LastUsedService do
it 'does not run on Geo secondaries', :clean_gitlab_redis_shared_state do it 'does not run on read-only GitLab instances', :clean_gitlab_redis_shared_state do
key = create(:key, last_used_at: 1.year.ago) key = create(:key, last_used_at: 1.year.ago)
original_time = key.last_used_at original_time = key.last_used_at
allow(::Gitlab::Geo).to receive(:secondary?).and_return(true) allow(::Gitlab::Database).to receive(:readonly?).and_return(true)
described_class.new(key).execute described_class.new(key).execute
expect(key.reload.last_used_at).to be_like_time(original_time) expect(key.reload.last_used_at).to be_like_time(original_time)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment