Class: Gitlab::Import::ImportFailureService

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/import/import_failure_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception:, import_state: nil, project_id: nil, error_source: nil, fail_import: false, metrics: false) ⇒ ImportFailureService

Returns a new instance of ImportFailureService.


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
# File 'lib/gitlab/import/import_failure_service.rb', line 24

def initialize(
  exception:,
  import_state: nil,
  project_id: nil,
  error_source: nil,
  fail_import: false,
  metrics: false
)

  if import_state.blank? && project_id.blank?
    raise ArgumentError, 'import_state OR project_id must be provided'
  end

  if project_id.blank?
    @import_state = import_state
    @project = import_state.project
  else
    @project = Project.find(project_id)
    @import_state = @project.import_state
  end

  @exception = exception
  @error_source = error_source
  @fail_import = fail_import
  @metrics = metrics
end

Class Method Details

.track(exception:, import_state: nil, project_id: nil, error_source: nil, fail_import: false, metrics: false) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/import/import_failure_service.rb', line 6

def self.track(
  exception:,
  import_state: nil,
  project_id: nil,
  error_source: nil,
  fail_import: false,
  metrics: false
)
  new(
    exception: exception,
    import_state: import_state,
    project_id: project_id,
    error_source: error_source,
    fail_import: fail_import,
    metrics: metrics
  ).execute
end

Instance Method Details

#executeObject


51
52
53
54
55
56
57
# File 'lib/gitlab/import/import_failure_service.rb', line 51

def execute
  track_exception
  persist_failure

  track_metrics if metrics
  import_state.mark_as_failed(exception.message) if fail_import
end