Commit 5e445fca authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ci-remove-failed-builds-from-ci-running-builds-table' into 'master'

Remove dangling running entries from ci running builds table

See merge request gitlab-org/gitlab!79444
parents 675d4fa1 0f69fdc0
# frozen_string_literal: true
class RemoveDanglingRunningBuilds < Gitlab::Database::Migration[1.0]
BATCH_SIZE = 100
disable_ddl_transaction!
def up
each_batch_range('ci_running_builds', of: BATCH_SIZE) do |min, max|
execute <<~SQL
DELETE FROM ci_running_builds
USING ci_builds
WHERE ci_builds.id = ci_running_builds.build_id
AND ci_builds.status = 'failed'
AND ci_builds.type = 'Ci::Build'
AND ci_running_builds.id BETWEEN #{min} AND #{max}
SQL
end
end
def down
# no-op
# This migration deletes data and it can not be reversed
end
end
0d121aeecdd6ace1516c2e9b84fefd47d963c4cbe22a0448728241d83da3742e
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!('remove_dangling_running_builds')
RSpec.describe RemoveDanglingRunningBuilds do
let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
let(:project) { table(:projects).create!(namespace_id: namespace.id) }
let(:runner) { table(:ci_runners).create!(runner_type: 1) }
let(:builds) { table(:ci_builds) }
let(:running_builds) { table(:ci_running_builds) }
let(:running_build) do
builds.create!(
name: 'test 1',
status: 'running',
project_id: project.id,
type: 'Ci::Build')
end
let(:failed_build) do
builds.create!(
name: 'test 2',
status: 'failed',
project_id: project.id,
type: 'Ci::Build')
end
let!(:running_metadata) do
running_builds.create!(
build_id: running_build.id,
project_id: project.id,
runner_id: runner.id,
runner_type:
runner.runner_type)
end
let!(:failed_metadata) do
running_builds.create!(
build_id: failed_build.id,
project_id: project.id,
runner_id: runner.id,
runner_type: runner.runner_type)
end
it 'removes failed builds' do
migrate!
expect(running_metadata.reload).to be_present
expect { failed_metadata.reload } .to raise_error(ActiveRecord::RecordNotFound)
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