Class: ContainerRegistry::Migration::GuardWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue
Defined in:
app/workers/container_registry/migration/guard_worker.rb

Constant Summary

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/workers/container_registry/migration/guard_worker.rb', line 19

def perform
  return unless Gitlab.com?

  repositories = ::ContainerRepository.with_stale_migration(step_before_timestamp)
                                      .limit(max_capacity)
  aborts_count = 0
  long_running_migrations = []

  # the #to_a is safe as the amount of entries is limited.
  # In addition, we're calling #each in the next line and we don't want two different SQL queries for these two lines
  (:stale_migrations_count, repositories.to_a.size)

  repositories.each do |repository|
    if actively_importing?(repository)
      # if a repository is actively importing but not yet long_running, do nothing
      if long_running_migration?(repository)
        long_running_migrations << repository
        cancel_long_running_migration(repository)
        aborts_count += 1
      end
    else
      repository.abort_import
      aborts_count += 1
    end
  end

  (:aborted_stale_migrations_count, aborts_count)

  if long_running_migrations.any?
    (:aborted_long_running_migration_ids, long_running_migrations.map(&:id))
    (:aborted_long_running_migration_paths, long_running_migrations.map(&:path))
  end
end