Keep failed renames in redis
This commit is contained in:
parent
d6a0c288c8
commit
171f2d97dc
|
@ -134,12 +134,24 @@ 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}"
|
||||
yield(path_before_rename, path_after_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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue