Class: Pages::MigrateFromLegacyStorageService

Inherits:
Object
  • Object
show all
Defined in:
app/services/pages/migrate_from_legacy_storage_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger, ignore_invalid_entries:, mark_projects_as_not_deployed:) ⇒ MigrateFromLegacyStorageService

Returns a new instance of MigrateFromLegacyStorageService.


5
6
7
8
9
10
11
12
13
# File 'app/services/pages/migrate_from_legacy_storage_service.rb', line 5

def initialize(logger, ignore_invalid_entries:, mark_projects_as_not_deployed:)
  @logger = logger
  @ignore_invalid_entries = ignore_invalid_entries
  @mark_projects_as_not_deployed = mark_projects_as_not_deployed

  @migrated = 0
  @errored = 0
  @counters_lock = Mutex.new
end

Instance Method Details

#execute_for_batch(project_ids) ⇒ Object


32
33
34
35
36
37
38
# File 'app/services/pages/migrate_from_legacy_storage_service.rb', line 32

def execute_for_batch(project_ids)
  batch = ProjectPagesMetadatum.only_on_legacy_storage.where(project_id: project_ids) # rubocop: disable CodeReuse/ActiveRecord

  process_batch(batch)

  { migrated: @migrated, errored: @errored }
end

#execute_with_threads(threads:, batch_size:) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/pages/migrate_from_legacy_storage_service.rb', line 15

def execute_with_threads(threads:, batch_size:)
  @queue = SizedQueue.new(1)

  migration_threads = start_migration_threads(threads)

  ProjectPagesMetadatum.only_on_legacy_storage.each_batch(of: batch_size) do |batch|
    @queue.push(batch)
  end

  @queue.close

  @logger.info(message: "Pages legacy storage migration: Waiting for threads to finish...")
  migration_threads.each(&:join)

  { migrated: @migrated, errored: @errored }
end