Commit 04aff518 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added geo:git:housekeeping:* rake tasks

parent 1e63d87b
......@@ -72,10 +72,16 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
Gitlab::Redis::SharedState.with { |redis| redis.del(fetches_since_gc_redis_key) }
end
def set_syncs_since_gc!(value)
return false if !value.is_a?(Integer) || value < 0
Gitlab::Redis::SharedState.with { |redis| redis.set(fetches_since_gc_redis_key, value) }
end
private
def fetches_since_gc_redis_key
"projects/#{project.id}/fetches_since_gc"
"projects/#{project_id}/fetches_since_gc"
end
def never_synced_repository?
......
namespace :geo do
namespace :git do
namespace :housekeeping do
desc "GitLab | Git | Housekeeping | Garbage Collection"
task gc: :gitlab_environment do
flag_for_housekeeping(Gitlab::CurrentSettings.housekeeping_gc_period)
end
desc "GitLab | Git | Housekeeping | Full Repack"
task full_repack: :gitlab_environment do
flag_for_housekeeping(Gitlab::CurrentSettings.housekeeping_full_repack_period)
end
desc "GitLab | Git | Housekeeping | Incremental Repack"
task incremental_repack: :gitlab_environment do
flag_for_housekeeping(Gitlab::CurrentSettings.housekeeping_incremental_repack_period)
end
def flag_for_housekeeping(period)
Geo::ProjectRegistry.select(:id, :project_id).find_in_batches do |batches|
batches.each do |registry|
registry.set_syncs_since_gc!(period - 1)
end
end
end
end
end
end
require 'rake_helper'
describe 'geo:git:housekeeping' do
set(:project) { create(:project, :repository) }
set(:registry) { ::Geo::ProjectRegistry.find_or_create_by!(project: project) }
shared_examples 'housekeeping task' do |task_name, period_name|
it "sets existing projects syncs_gc count to #{period_name}-1" do
period = Gitlab::CurrentSettings.send(period_name)
expect { run_rake_task(task_name) }.to change { registry.syncs_since_gc }.to(period - 1)
end
end
before do
Rake.application.rake_require 'tasks/geo/git'
end
after do
registry.reset_syncs_since_gc!
end
describe 'geo:git:housekeeping:gc' do
it_behaves_like 'housekeeping task', 'geo:git:housekeeping:gc', :housekeeping_gc_period
end
describe 'geo:git:housekeeping:full_repack' do
it_behaves_like 'housekeeping task', 'geo:git:housekeeping:full_repack', :housekeeping_full_repack_period
end
describe 'geo:git:housekeeping:incremental_repack' do
it_behaves_like 'housekeeping task', 'geo:git:housekeeping:incremental_repack', :housekeeping_incremental_repack_period
end
end
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