summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/background_migration
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/background_migration')
-rw-r--r--lib/gitlab/database/background_migration/batched_job.rb18
-rw-r--r--lib/gitlab/database/background_migration/batched_migration.rb2
2 files changed, 8 insertions, 12 deletions
diff --git a/lib/gitlab/database/background_migration/batched_job.rb b/lib/gitlab/database/background_migration/batched_job.rb
index 503172dd750..290fa51692a 100644
--- a/lib/gitlab/database/background_migration/batched_job.rb
+++ b/lib/gitlab/database/background_migration/batched_job.rb
@@ -12,17 +12,6 @@ module Gitlab
MAX_ATTEMPTS = 3
STUCK_JOBS_TIMEOUT = 1.hour.freeze
- belongs_to :batched_migration, foreign_key: :batched_background_migration_id
-
- scope :active, -> { where(status: [:pending, :running]) }
- scope :stuck, -> { active.where('updated_at <= ?', STUCK_JOBS_TIMEOUT.ago) }
- scope :retriable, -> {
- failed_jobs = where(status: :failed).where('attempts < ?', MAX_ATTEMPTS)
-
- from_union([failed_jobs, self.stuck])
- }
- scope :except_succeeded, -> { where(status: self.statuses.except(:succeeded).values) }
-
enum status: {
pending: 0,
running: 1,
@@ -30,7 +19,14 @@ module Gitlab
succeeded: 3
}
+ belongs_to :batched_migration, foreign_key: :batched_background_migration_id
+
+ scope :active, -> { where(status: [:pending, :running]) }
+ scope :stuck, -> { active.where('updated_at <= ?', STUCK_JOBS_TIMEOUT.ago) }
+ scope :retriable, -> { from_union([failed.where('attempts < ?', MAX_ATTEMPTS), self.stuck]) }
+ scope :except_succeeded, -> { where(status: self.statuses.except(:succeeded).values) }
scope :successful_in_execution_order, -> { where.not(finished_at: nil).succeeded.order(:finished_at) }
+ scope :with_preloads, -> { preload(:batched_migration) }
delegate :job_class, :table_name, :column_name, :job_arguments,
to: :batched_migration, prefix: :migration
diff --git a/lib/gitlab/database/background_migration/batched_migration.rb b/lib/gitlab/database/background_migration/batched_migration.rb
index 2844cbe4a74..2f066039874 100644
--- a/lib/gitlab/database/background_migration/batched_migration.rb
+++ b/lib/gitlab/database/background_migration/batched_migration.rb
@@ -113,7 +113,7 @@ module Gitlab
end
def smoothed_time_efficiency(number_of_jobs: 10, alpha: 0.2)
- jobs = batched_jobs.successful_in_execution_order.reverse_order.limit(number_of_jobs)
+ jobs = batched_jobs.successful_in_execution_order.reverse_order.limit(number_of_jobs).with_preloads
return if jobs.size < number_of_jobs