Commit 545d0a04 authored by Michael Kozono's avatar Michael Kozono

Propagate broadcast messages to secondaries

parent c79679f6
class BroadcastMessage < ActiveRecord::Base
prepend EE::BroadcastMessage
include CacheMarkdownField
include Sortable
......@@ -19,7 +20,7 @@ class BroadcastMessage < ActiveRecord::Base
after_commit :flush_redis_cache
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?
......@@ -36,6 +37,10 @@ class BroadcastMessage < ActiveRecord::Base
where('ends_at > :now', now: Time.zone.now).order_id_asc
end
def self.cache_expires_in
nil
end
def active?
started? && !ended?
end
......
......@@ -174,13 +174,6 @@ will take to finish syncing. An example message would be:
> A scheduled maintenance will take place at XX:XX UTC. We expect it to take
less than 1 hour.
Until [issue #4930][ee-4930] is resolved, you may need to clear the Redis cache
for the broadcast message to show. On the **secondary**, run:
```
sudo gitlab-rake cache:clear:redis
```
## Prevent updates to the **primary**
Until a [read-only mode][ce-19739] is implemented, updates must be prevented
......
module EE
# BroadcastMessage EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be prepended in the `BroadcastMessage` model
module BroadcastMessage
extend ActiveSupport::Concern
module ClassMethods
extend ::Gitlab::Utils::Override
override :cache_expires_in
def cache_expires_in
if ::Gitlab::Geo.secondary?
30.seconds
else
super
end
end
end
end
end
---
title: 'Geo: Propagate broadcast messages to secondaries'
merge_request: 5303
author:
type: fixed
require 'spec_helper'
describe BroadcastMessage do
subject { build(:broadcast_message) }
describe '.current', :use_clean_rails_memory_store_caching do
context 'without Geo' do
it 'caches the output for a long time' do
expect(Gitlab::Geo).to receive(:enabled?).and_return(false).exactly(2).times
create(:broadcast_message)
expect(described_class).to receive(:where).and_call_original.once
described_class.current
Timecop.travel(1.year) do
described_class.current
end
end
end
context 'with Geo' do
context 'on the primary' do
it 'caches the output for a long time' do
expect(Gitlab::Geo).to receive(:secondary?).and_return(false).exactly(2).times
create(:broadcast_message)
expect(described_class).to receive(:where).and_call_original.once
described_class.current
Timecop.travel(1.year) do
described_class.current
end
end
end
context 'on a secondary' do
it 'caches the output for a short time' do
expect(Gitlab::Geo).to receive(:secondary?).and_return(true).exactly(3).times
create(:broadcast_message)
expect(described_class).to receive(:where).and_call_original.once
described_class.current
Timecop.travel(20.seconds) do
described_class.current
end
expect(described_class).to receive(:where).and_call_original.once
Timecop.travel(40.seconds) do
described_class.current
end
end
end
end
end
end
......@@ -51,7 +51,11 @@ describe BroadcastMessage do
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
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