Class: ProjectImportState

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, ImportState::SidekiqJobTracker
Defined in:
app/models/project_import_state.rb

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#in_progress?Boolean

Returns:

  • (Boolean)

98
99
100
# File 'app/models/project_import_state.rb', line 98

def in_progress?
  scheduled? || started?
end

#mark_as_failed(error_message) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/project_import_state.rb', line 79

def mark_as_failed(error_message)
  original_errors = errors.dup
  sanitized_message = Gitlab::UrlSanitizer.sanitize(error_message)

  fail_op

  update_column(:last_error, sanitized_message)
rescue ActiveRecord::ActiveRecordError => e
  Gitlab::Import::Logger.error(
    message: 'Error setting import status to failed',
    error: e.message,
    original_error: sanitized_message
  )
ensure
  @errors = original_errors
end

#relation_hard_failures(limit:) ⇒ Object


75
76
77
# File 'app/models/project_import_state.rb', line 75

def relation_hard_failures(limit:)
  project.import_failures.hard_failures_by_correlation_id(correlation_id).limit(limit)
end

#started?Boolean

Returns:

  • (Boolean)

102
103
104
105
# File 'app/models/project_import_state.rb', line 102

def started?
  # import? does SQL work so only run it if it looks like there's an import running
  status == 'started' && project.import?
end