Use Geo roles to configure Sidekiq cron jobs

parent 340b2f79
...@@ -623,6 +623,8 @@ production: &base ...@@ -623,6 +623,8 @@ production: &base
# port: 3808 # port: 3808
## GitLab Geo settings (EE-only) ## GitLab Geo settings (EE-only)
geo_primary_role:
enable: false
geo_secondary_role: geo_secondary_role:
enable: false enable: false
...@@ -709,6 +711,8 @@ test: ...@@ -709,6 +711,8 @@ test:
user_filter: '' user_filter: ''
group_base: 'ou=groups,dc=example,dc=com' group_base: 'ou=groups,dc=example,dc=com'
admin_group: '' admin_group: ''
geo_primary_role:
enable: true
geo_secondary_role: geo_secondary_role:
enable: true enable: true
......
...@@ -342,6 +342,8 @@ Settings.pages['external_https'] ||= false unless Settings.pages['external_http ...@@ -342,6 +342,8 @@ Settings.pages['external_https'] ||= false unless Settings.pages['external_http
# Geo # Geo
# #
Settings.gitlab['geo_status_timeout'] ||= 10 Settings.gitlab['geo_status_timeout'] ||= 10
Settings['geo_primary_role'] ||= Settingslogic.new({})
Settings.geo_primary_role['enable'] = false if Settings.geo_primary_role['enable'].nil?
Settings['geo_secondary_role'] ||= Settingslogic.new({}) Settings['geo_secondary_role'] ||= Settingslogic.new({})
Settings.geo_secondary_role['enable'] = false if Settings.geo_secondary_role['enable'].nil? Settings.geo_secondary_role['enable'] = false if Settings.geo_secondary_role['enable'].nil?
......
...@@ -46,6 +46,10 @@ module Gitlab ...@@ -46,6 +46,10 @@ module Gitlab
Rails.configuration.respond_to?(:geo_database) Rails.configuration.respond_to?(:geo_database)
end end
def self.primary_role_enabled?
Gitlab.config.geo_primary_role['enable']
end
def self.secondary_role_enabled? def self.secondary_role_enabled?
Gitlab.config.geo_secondary_role['enable'] Gitlab.config.geo_secondary_role['enable']
end end
...@@ -98,9 +102,9 @@ module Gitlab ...@@ -98,9 +102,9 @@ module Gitlab
end end
def self.configure_cron_jobs! def self.configure_cron_jobs!
if self.primary? if self.primary_role_enabled?
self.configure_primary_jobs! self.configure_primary_jobs!
elsif self.secondary? elsif self.secondary_role_enabled?
self.configure_secondary_jobs! self.configure_secondary_jobs!
else else
self.disable_all_jobs! self.disable_all_jobs!
......
...@@ -127,7 +127,9 @@ describe Gitlab::Geo, lib: true do ...@@ -127,7 +127,9 @@ describe Gitlab::Geo, lib: true do
end end
it 'activates cron jobs for primary' do it 'activates cron jobs for primary' do
allow(described_class).to receive(:primary?).and_return(true) allow(described_class).to receive(:primary_role_enabled?).and_return(true)
allow(described_class).to receive(:secondary_role_enabled?).and_return(false)
described_class.configure_cron_jobs! described_class.configure_cron_jobs!
expect(described_class.bulk_notify_job).to be_enabled expect(described_class.bulk_notify_job).to be_enabled
...@@ -136,7 +138,9 @@ describe Gitlab::Geo, lib: true do ...@@ -136,7 +138,9 @@ describe Gitlab::Geo, lib: true do
end end
it 'activates cron jobs for secondary' do it 'activates cron jobs for secondary' do
allow(described_class).to receive(:secondary?).and_return(true) allow(described_class).to receive(:primary_role_enabled?).and_return(false)
allow(described_class).to receive(:secondary_role_enabled?).and_return(true)
described_class.configure_cron_jobs! described_class.configure_cron_jobs!
expect(described_class.bulk_notify_job).not_to be_enabled expect(described_class.bulk_notify_job).not_to be_enabled
...@@ -145,6 +149,9 @@ describe Gitlab::Geo, lib: true do ...@@ -145,6 +149,9 @@ describe Gitlab::Geo, lib: true do
end end
it 'deactivates all jobs when Geo is not active' do it 'deactivates all jobs when Geo is not active' do
allow(described_class).to receive(:primary_role_enabled?).and_return(false)
allow(described_class).to receive(:secondary_role_enabled?).and_return(false)
described_class.configure_cron_jobs! described_class.configure_cron_jobs!
expect(described_class.bulk_notify_job).not_to be_enabled expect(described_class.bulk_notify_job).not_to be_enabled
......
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