Skip to content
Snippets Groups Projects
Commit b6d5c450 authored by Andreas Brandl's avatar Andreas Brandl
Browse files

Add database reindexing cronjob

Relates to gitlab#249662
parent 55d71a63
No related branches found
No related tags found
Loading
---
title: Add database reindexing cronjob
merge_request: 4602
author:
type: added
......@@ -388,6 +388,11 @@ default['gitlab']['gitlab-rails']['db_statement_timeout'] = nil
default['gitlab']['gitlab-rails']['db_fdw'] = nil
default['gitlab']['gitlab-rails']['db_connect_timeout'] = nil
default['gitlab']['gitlab-rails']['database_reindexing']['enable'] = false
default['gitlab']['gitlab-rails']['database_reindexing']['hour'] = '*'
default['gitlab']['gitlab-rails']['database_reindexing']['minute'] = 0
default['gitlab']['gitlab-rails']['database_reindexing']['day_of_week'] = '0,6'
default['gitlab']['gitlab-rails']['redis_host'] = "127.0.0.1"
default['gitlab']['gitlab-rails']['redis_port'] = nil
default['gitlab']['gitlab-rails']['redis_ssl'] = false
......
#
# Copyright:: Copyright (c) 2020 GitLab B.V.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
reindexing = node['gitlab']['gitlab-rails']['database_reindexing'] || {}
if reindexing['enable']
include_recipe "crond::enable"
crond_job 'database-reindexing' do
user "root"
hour reindexing['hour'] || 0
minute reindexing['minute'] || 0
month reindexing['month'] || '*'
day_of_month reindexing['day_of_month'] || '*'
day_of_week reindexing['day_of_week'] || '*'
command "/opt/gitlab/bin/gitlab-rake gitlab:db:reindex"
end
else
crond_job 'database-reindexing' do
action :delete
end
include_recipe "crond::disable"
end
require 'chef_helper'
RSpec.describe 'gitlab::database-reindexing' do
let(:chef_run) { converge_config('gitlab::database_reindexing') }
before do
allow(Gitlab).to receive(:[]).and_call_original
end
context 'database reindexing enabled' do
context 'with defaults' do
before do
stub_gitlab_rb(gitlab_rails: { database_reindexing: { enable: true } })
end
it 'enables crond' do
expect(chef_run).to include_recipe('crond::enable')
end
it 'adds a crond_job with default schedule' do
expect(chef_run).to create_crond_job('database-reindexing').with(
user: "root",
hour: '*',
minute: 0,
month: '*',
day_of_month: '*',
day_of_week: '0,6',
command: "/opt/gitlab/bin/gitlab-rake gitlab:db:reindex"
)
end
end
context 'with specific schedule' do
let(:config) do
{
enable: true,
hour: 10,
minute: 5,
month: 3,
day_of_month: 2,
day_of_week: 1
}
end
it 'adds a crond_job with the configured schedule' do
stub_gitlab_rb(gitlab_rails: { database_reindexing: config })
expect(chef_run).to create_crond_job('database-reindexing').with(
user: "root",
hour: 10,
minute: 5,
month: 3,
day_of_week: 1,
command: "/opt/gitlab/bin/gitlab-rake gitlab:db:reindex"
)
end
end
end
context 'database reindexing disabled' do
before do
stub_gitlab_rb(gitlab_rails: { database_reindexing: { enable: false } })
end
it 'disables crond' do
expect(chef_run).to include_recipe('crond::disable')
expect(chef_run).not_to include_recipe('crond::enable')
end
it 'removes the database-reindexing cronjob' do
expect(chef_run).to delete_crond_job('database-reindexing')
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment