summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/migrations/test_background_runner.rb
blob: 6da2e098d4312810a5ffaff390480b18a2ea403d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Gitlab
  module Database
    module Migrations
      class TestBackgroundRunner < BaseBackgroundRunner
        def initialize(result_dir:)
          super(result_dir: result_dir)
          @job_coordinator = Gitlab::BackgroundMigration.coordinator_for_database(Gitlab::Database::MAIN_DATABASE_NAME)
        end

        def traditional_background_migrations
          @job_coordinator.pending_jobs
        end

        def jobs_by_migration_name
          traditional_background_migrations.group_by { |j| class_name_for_job(j) }
                                           .transform_values(&:shuffle)
        end

        private

        def run_job(job)
          Gitlab::BackgroundMigration.perform(job.args[0], job.args[1])
        end

        def class_name_for_job(job)
          job.args[0]
        end
      end
    end
  end
end