diff options
Diffstat (limited to 'lib/gitlab/database/background_migration')
-rw-r--r-- | lib/gitlab/database/background_migration/batched_job.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/database/background_migration/batched_migration.rb | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/gitlab/database/background_migration/batched_job.rb b/lib/gitlab/database/background_migration/batched_job.rb index 869b97b8ac0..9a1dc4ee17d 100644 --- a/lib/gitlab/database/background_migration/batched_job.rb +++ b/lib/gitlab/database/background_migration/batched_job.rb @@ -30,7 +30,7 @@ module Gitlab scope :successful_in_execution_order, -> { where.not(finished_at: nil).succeeded.order(:finished_at) } - delegate :aborted?, :job_class, :table_name, :column_name, :job_arguments, + delegate :job_class, :table_name, :column_name, :job_arguments, to: :batched_migration, prefix: :migration attribute :pause_ms, :integer, default: 100 diff --git a/lib/gitlab/database/background_migration/batched_migration.rb b/lib/gitlab/database/background_migration/batched_migration.rb index e85162f355e..36e89023c86 100644 --- a/lib/gitlab/database/background_migration/batched_migration.rb +++ b/lib/gitlab/database/background_migration/batched_migration.rb @@ -14,12 +14,20 @@ module Gitlab class_name: 'Gitlab::Database::BackgroundMigration::BatchedJob', foreign_key: :batched_background_migration_id + validates :job_arguments, uniqueness: { + scope: [:job_class_name, :table_name, :column_name] + } + scope :queue_order, -> { order(id: :asc) } + scope :queued, -> { where(status: [:active, :paused]) } + scope :for_configuration, ->(job_class_name, table_name, column_name, job_arguments) do + where(job_class_name: job_class_name, table_name: table_name, column_name: column_name) + .where("job_arguments = ?", job_arguments.to_json) # rubocop:disable Rails/WhereEquals + end enum status: { paused: 0, active: 1, - aborted: 2, finished: 3, failed: 4 } @@ -30,6 +38,14 @@ module Gitlab active.queue_order.first end + def self.successful_rows_counts(migrations) + BatchedJob + .succeeded + .where(batched_background_migration_id: migrations) + .group(:batched_background_migration_id) + .sum(:batch_size) + end + def interval_elapsed?(variance: 0) return true unless last_job |