Merge branch 'mk/geo/backport-broadcast-message-cache-expiration-hook' into 'master'

[CE Backport] Propagate broadcast messages to secondaries

See merge request gitlab-org/gitlab-ce!18324
This commit is contained in:
Nick Thomas 2018-04-11 19:04:10 +00:00
commit 84c70f4335
2 changed files with 10 additions and 2 deletions

View file

@ -19,7 +19,7 @@ class BroadcastMessage < ActiveRecord::Base
after_commit :flush_redis_cache after_commit :flush_redis_cache
def self.current def self.current
messages = Rails.cache.fetch(CACHE_KEY) { current_and_future_messages.to_a } messages = Rails.cache.fetch(CACHE_KEY, expires_in: cache_expires_in) { current_and_future_messages.to_a }
return messages if messages.empty? return messages if messages.empty?
@ -36,6 +36,10 @@ class BroadcastMessage < ActiveRecord::Base
where('ends_at > :now', now: Time.zone.now).order_id_asc where('ends_at > :now', now: Time.zone.now).order_id_asc
end end
def self.cache_expires_in
nil
end
def active? def active?
started? && !ended? started? && !ended?
end end

View file

@ -51,7 +51,11 @@ describe BroadcastMessage do
expect(described_class).to receive(:where).and_call_original.once expect(described_class).to receive(:where).and_call_original.once
2.times { described_class.current } described_class.current
Timecop.travel(1.year) do
described_class.current
end
end end
it 'includes messages that need to be displayed in the future' do it 'includes messages that need to be displayed in the future' do