summaryrefslogtreecommitdiff
path: root/app/workers/storage_migrator_worker.rb
blob: b48ead799b91e78f2f3a604222bdc3042d6ab62a (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
class StorageMigratorWorker
  include Sidekiq::Worker
  include DedicatedSidekiqQueue

  BATCH_SIZE = 100

  def perform(start, finish)
    projects = build_relation(start, finish)

    projects.with_route.find_each(batch_size: BATCH_SIZE) do |project|
      Rails.logger.info "Starting storage migration of #{project.full_path} (ID=#{project.id})..."

      begin
        project.migrate_to_hashed_storage!
      rescue => err
        Rails.logger.error("#{err.message} migrating storage of #{project.full_path} (ID=#{project.id}), trace - #{err.backtrace}")
      end
    end
  end

  def build_relation(start, finish)
    relation = Project
    table = Project.arel_table

    relation = relation.where(table[:id].gteq(start)) if start
    relation = relation.where(table[:id].lteq(finish)) if finish

    relation
  end
end