Commit 435e913d authored by Stan Hu's avatar Stan Hu Committed by Dylan Griffith

Only load usage ping cron schedule for Sidekiq

Previously the initializer always loaded the `application_settings`
table in the initializer, even for Rake tasks (e.g. `rake
db:setup). This was done because the usage ping worker needed to load
the UUID of theins instance from the database to calculate the usage
ping schedule. However, cron schedules are only needed by Sidekiq, so we
can defer the calculation of this value in the Sidekiq initializer.

When loading application settings from the database, this should make it
possible for us to raise errors when the connection is not present since
this appears to be the only setting that is actually needed at init
time.

This came out of a discussion in
https://gitlab.com/gitlab-org/gitlab/issues/205640.
parent 0613aa98
---
title: Only load usage ping cron schedule for Sidekiq
merge_request: 25325
author:
type: other
......@@ -446,7 +446,7 @@ Settings.cron_jobs['stuck_import_jobs_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['stuck_import_jobs_worker']['cron'] ||= '15 * * * *'
Settings.cron_jobs['stuck_import_jobs_worker']['job_class'] = 'StuckImportJobsWorker'
Settings.cron_jobs['gitlab_usage_ping_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['gitlab_usage_ping_worker']['cron'] ||= Settings.__send__(:cron_for_usage_ping)
Settings.cron_jobs['gitlab_usage_ping_worker']['cron'] ||= nil # This is dynamically loaded in the sidekiq initializer
Settings.cron_jobs['gitlab_usage_ping_worker']['job_class'] = 'GitlabUsagePingWorker'
Settings.cron_jobs['stuck_merge_jobs_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['stuck_merge_jobs_worker']['cron'] ||= '0 */2 * * *'
......
# frozen_string_literal: true
require 'sidekiq/web'
def enable_reliable_fetch?
......@@ -71,6 +73,8 @@ Sidekiq.configure_server do |config|
Sidekiq::ReliableFetch.setup_reliable_fetch!(config)
end
Gitlab.config.load_dynamic_cron_schedules!
# Sidekiq-cron: load recurring jobs from gitlab.yml
# UGLY Hack to get nested hash from settingslogic
cron_jobs = JSON.parse(Gitlab.config.cron_jobs.to_json)
......
# frozen_string_literal: true
require 'settingslogic'
require 'digest/md5'
......@@ -143,6 +145,10 @@ class Settings < Settingslogic
Gitlab::Application.secrets.db_key_base
end
def load_dynamic_cron_schedules!
cron_jobs['gitlab_usage_ping_worker']['cron'] ||= cron_for_usage_ping
end
private
def base_url(config)
......
......@@ -9,6 +9,12 @@ describe Settings do
end
end
describe '.load_dynamic_cron_schedules!' do
it 'generates a valid cron schedule' do
expect(Fugit::Cron.parse(described_class.load_dynamic_cron_schedules!)).to be_a(Fugit::Cron)
end
end
describe '.attr_encrypted_db_key_base_truncated' do
it 'is a string with maximum 32 bytes size' do
expect(described_class.attr_encrypted_db_key_base_truncated.bytesize)
......
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