Class: Projects::AfterImportWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker
Defined in:
app/workers/projects/after_import_worker.rb

Constant Summary collapse

RESERVED_REF_PREFIXES =
Repository::RESERVED_REFS_NAMES.map { |n| File.join('refs', n, '/') }

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

#perform(project_id) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/workers/projects/after_import_worker.rb', line 14

def perform(project_id)
  @project = Project.find(project_id)

  service = Repositories::HousekeepingService.new(@project)

  service.execute do
    import_failure_service.with_retry(action: 'delete_all_refs') do
      repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
    end
  end

  # Right now we don't actually have a way to know if a project
  # import actually changed, so we increment the counter to avoid
  # causing GC to run every time.
  service.increment!
rescue Repositories::HousekeepingService::LeaseTaken => e
  Gitlab::Import::Logger.info(
    message: 'Project housekeeping failed',
    project_full_path: @project.full_path,
    project_id: @project.id,
    'error.message' => e.message
  )
end