Class: BulkImports::EntityWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker
Defined in:
app/workers/bulk_imports/entity_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

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

#perform(entity_id, current_stage = nil) ⇒ Object



14
15
16
17
18
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/workers/bulk_imports/entity_worker.rb', line 14

def perform(entity_id, current_stage = nil)
  @entity = ::BulkImports::Entity.find(entity_id)

  if stage_running?(entity_id, current_stage)
    logger.info(
      structured_payload(
        bulk_import_entity_id: entity_id,
        bulk_import_id: entity.bulk_import_id,
        bulk_import_entity_type: entity.source_type,
        source_full_path: entity.source_full_path,
        current_stage: current_stage,
        message: 'Stage running',
        source_version: source_version,
        importer: 'gitlab_migration'
      )
    )

    return
  end

  logger.info(
    structured_payload(
      bulk_import_entity_id: entity_id,
      bulk_import_id: entity.bulk_import_id,
      bulk_import_entity_type: entity.source_type,
      source_full_path: entity.source_full_path,
      current_stage: current_stage,
      message: 'Stage starting',
      source_version: source_version,
      importer: 'gitlab_migration'
    )
  )

  next_pipeline_trackers_for(entity_id).each do |pipeline_tracker|
    BulkImports::PipelineWorker.perform_async(
      pipeline_tracker.id,
      pipeline_tracker.stage,
      entity_id
    )
  end
rescue StandardError => e
  log_exception(e,
    {
      bulk_import_entity_id: entity_id,
      bulk_import_id: entity.bulk_import_id,
      bulk_import_entity_type: entity.source_type,
      source_full_path: entity.source_full_path,
      current_stage: current_stage,
      message: 'Entity failed',
      source_version: source_version,
      importer: 'gitlab_migration'
    }
  )

  Gitlab::ErrorTracking.track_exception(
    e,
    bulk_import_entity_id: entity_id,
    bulk_import_id: entity.bulk_import_id,
    bulk_import_entity_type: entity.source_type,
    source_full_path: entity.source_full_path,
    source_version: source_version,
    importer: 'gitlab_migration'
  )

  entity.fail_op!
end