Commit 87b58670 authored by rossfuhrman's avatar rossfuhrman Committed by Tiger Watson

Reschedule migration for self-managed

Reschedules migration to recalculate finding siginatures and limits it
to self-managed.

Changelog: other
EE: true
parent c29e5b6d
......@@ -8,15 +8,7 @@ class ScheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Dat
disable_ddl_transaction!
def up
return unless Gitlab.ee?
queue_background_migration_jobs_by_range_at_intervals(
define_batchable_model('vulnerability_finding_signatures'),
MIGRATION,
DELAY_INTERVAL,
batch_size: BATCH_SIZE,
track_jobs: true
)
# no-op based on https://docs.gitlab.com/ee/development/background_migrations.html#rescheduling-background-migrations
end
def down
......
# frozen_string_literal: true
class SelfManagedRescheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Database::Migration[1.0]
MIGRATION = 'RecalculateVulnerabilityFindingSignaturesForFindings'
BATCH_SIZE = 1_000
DELAY_INTERVAL = 2.minutes
disable_ddl_transaction!
def up
# Only run migration for self-managed
return if ::Gitlab.com?
# Vulnerability Finding Signatures is an EE only feature
return unless Gitlab.ee?
delete_queued_jobs(MIGRATION)
requeue_background_migration_jobs_by_range_at_intervals(
MIGRATION,
DELAY_INTERVAL,
batch_size: BATCH_SIZE
)
end
def down
# no-op
end
end
9b33f6e0c13acbf1adfc1b70f75418ceabc000a748c9216328ef36f1b8716ded
\ No newline at end of file
......@@ -33,6 +33,8 @@ module EE
signatures.delete_all
ApplicationRecord.legacy_bulk_insert(:vulnerability_finding_signatures, rows) # rubocop:disable Gitlab/BulkInsert
mark_job_as_succeeded(start_id, stop_id)
end
rescue StandardError => e
logger.error(
......@@ -69,6 +71,13 @@ module EE
nil
end
def mark_job_as_succeeded(*arguments)
::Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded(
self.class.name.demodulize,
arguments
)
end
def logger
@logger ||= ::Gitlab::BackgroundMigration::Logger.build
end
......
......@@ -51,16 +51,17 @@ RSpec.describe ScheduleRecalculateVulnerabilityFindingSignaturesForFindings, :mi
let_it_be(:finding3) { findings.create!(finding_params) }
let_it_be(:signature3) { vulnerability_finding_signatures.create!(finding_id: finding3.id, algorithm_type: 0, signature_sha: ::Digest::SHA1.digest(SecureRandom.hex(50))) }
it 'schedules the background jobs', :aggregate_failure do
# this migration is now a no-op
it 'does not schedule the background jobs', :aggregate_failure do
Sidekiq::Testing.fake! do
freeze_time do
migrate!
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
expect(BackgroundMigrationWorker.jobs.size).to eq(0)
expect(described_class::MIGRATION)
.to be_scheduled_migration_with_multiple_args(signature1.id, signature2.id)
.not_to be_scheduled_migration_with_multiple_args(signature1.id, signature2.id)
expect(described_class::MIGRATION)
.to be_scheduled_migration_with_multiple_args(signature3.id, signature3.id)
.not_to be_scheduled_migration_with_multiple_args(signature3.id, signature3.id)
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