Commit 171f2d97 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Keep failed renames in redis

parent d6a0c288
......@@ -134,13 +134,25 @@ module Gitlab
def reverts_for_type(type)
key = redis_key_for_type(type)
Gitlab::Redis.with do |redis|
failed_reverts = []
while rename_info = redis.lpop(key)
path_before_rename, path_after_rename = JSON.parse(rename_info)
say "renaming #{type} from #{path_after_rename} back to #{path_before_rename}"
begin
yield(path_before_rename, path_after_rename)
rescue StandardError => e
failed_reverts << rename_info
say "Renaming #{type} from back to #{path_before_rename} failed. "\
"Review the error and try again by running the `down` action. \n"\
"#{e.message}: \n #{e.backtrace.join("\n")}"
end
end
failed_reverts.each { |rename_info| redis.lpush(key, rename_info) }
end
end
def redis_key_for_type(type)
......
......@@ -257,5 +257,24 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca
expect { |b| subject.reverts_for_type('namespace', &b) }
.to yield_with_args('namespace_path', 'new_namespace_path')
end
it 'keeps the revert in redis if it failed' do
subject.track_rename('project', 'old_path', 'new_path')
subject.reverts_for_type('project') do
raise 'whatever happens, keep going!'
end
key = 'rename:FakeRenameReservedPathMigrationV1:project'
stored_renames = nil
rename_count = 0
Gitlab::Redis.with do |redis|
stored_renames = redis.lrange(key, 0, 1)
rename_count = redis.llen(key)
end
expect(rename_count).to eq(1)
expect(JSON.parse(stored_renames.first)).to eq(%w(old_path new_path))
end
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