Commit 94fc61ac authored by Tiger Watson's avatar Tiger Watson

Merge branch 'self-managed-reschedule-recalculating-finding-signatures' into 'master'

Reschedule migration for self-managed

See merge request gitlab-org/gitlab!78509
parents 51634ee0 87b58670
...@@ -8,15 +8,7 @@ class ScheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Dat ...@@ -8,15 +8,7 @@ class ScheduleRecalculateVulnerabilityFindingSignaturesForFindings < Gitlab::Dat
disable_ddl_transaction! disable_ddl_transaction!
def up def up
return unless Gitlab.ee? # no-op based on https://docs.gitlab.com/ee/development/background_migrations.html#rescheduling-background-migrations
queue_background_migration_jobs_by_range_at_intervals(
define_batchable_model('vulnerability_finding_signatures'),
MIGRATION,
DELAY_INTERVAL,
batch_size: BATCH_SIZE,
track_jobs: true
)
end end
def down 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 ...@@ -33,6 +33,8 @@ module EE
signatures.delete_all signatures.delete_all
ApplicationRecord.legacy_bulk_insert(:vulnerability_finding_signatures, rows) # rubocop:disable Gitlab/BulkInsert ApplicationRecord.legacy_bulk_insert(:vulnerability_finding_signatures, rows) # rubocop:disable Gitlab/BulkInsert
mark_job_as_succeeded(start_id, stop_id)
end end
rescue StandardError => e rescue StandardError => e
logger.error( logger.error(
...@@ -69,6 +71,13 @@ module EE ...@@ -69,6 +71,13 @@ module EE
nil nil
end end
def mark_job_as_succeeded(*arguments)
::Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded(
self.class.name.demodulize,
arguments
)
end
def logger def logger
@logger ||= ::Gitlab::BackgroundMigration::Logger.build @logger ||= ::Gitlab::BackgroundMigration::Logger.build
end end
......
...@@ -51,16 +51,17 @@ RSpec.describe ScheduleRecalculateVulnerabilityFindingSignaturesForFindings, :mi ...@@ -51,16 +51,17 @@ RSpec.describe ScheduleRecalculateVulnerabilityFindingSignaturesForFindings, :mi
let_it_be(:finding3) { findings.create!(finding_params) } 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))) } 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 Sidekiq::Testing.fake! do
freeze_time do freeze_time do
migrate! migrate!
expect(BackgroundMigrationWorker.jobs.size).to eq(2) expect(BackgroundMigrationWorker.jobs.size).to eq(0)
expect(described_class::MIGRATION) 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) 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 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