Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
545d0a04
Commit
545d0a04
authored
Apr 09, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Propagate broadcast messages to secondaries
parent
c79679f6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
9 deletions
+101
-9
app/models/broadcast_message.rb
app/models/broadcast_message.rb
+6
-1
doc/administration/geo/disaster_recovery/planned_failover.md
doc/administration/geo/disaster_recovery/planned_failover.md
+0
-7
ee/app/models/ee/broadcast_message.rb
ee/app/models/ee/broadcast_message.rb
+22
-0
ee/changelogs/unreleased/mk-geo-fix-broadcast-message-on-secondary.yml
.../unreleased/mk-geo-fix-broadcast-message-on-secondary.yml
+5
-0
ee/spec/models/broadcast_message_spec.rb
ee/spec/models/broadcast_message_spec.rb
+63
-0
spec/models/broadcast_message_spec.rb
spec/models/broadcast_message_spec.rb
+5
-1
No files found.
app/models/broadcast_message.rb
View file @
545d0a04
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
...
...
doc/administration/geo/disaster_recovery/planned_failover.md
View file @
545d0a04
...
...
@@ -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
...
...
ee/app/models/ee/broadcast_message.rb
0 → 100644
View file @
545d0a04
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
ee/changelogs/unreleased/mk-geo-fix-broadcast-message-on-secondary.yml
0 → 100644
View file @
545d0a04
---
title
:
'
Geo:
Propagate
broadcast
messages
to
secondaries'
merge_request
:
5303
author
:
type
:
fixed
ee/spec/models/broadcast_message_spec.rb
0 → 100644
View file @
545d0a04
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
spec/models/broadcast_message_spec.rb
View file @
545d0a04
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment