Commit 1ce0595b authored by Michael Kozono's avatar Michael Kozono

Backport: Propagate broadcast messages to secondaries

parent 37a56324
...@@ -19,7 +19,7 @@ class BroadcastMessage < ActiveRecord::Base ...@@ -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 ...@@ -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
......
...@@ -51,7 +51,11 @@ describe BroadcastMessage do ...@@ -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
......
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