Class: ProjectImportState

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

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Instance Attribute Details

#safe_import_urlObject

Returns the value of attribute safe_import_url.



9
10
11
# File 'app/models/project_import_state.rb', line 9

def safe_import_url
  @safe_import_url
end

#user_mapping_enabledObject

Returns the value of attribute user_mapping_enabled.



9
10
11
# File 'app/models/project_import_state.rb', line 9

def user_mapping_enabled
  @user_mapping_enabled
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'app/models/project_import_state.rb', line 153

def completed?
  finished? || failed? || canceled?
end

#expire_etag_cacheObject



106
107
108
109
110
111
112
113
114
# File 'app/models/project_import_state.rb', line 106

def expire_etag_cache
  if realtime_changes_path
    Gitlab::EtagCaching::Store.new.tap do |store|
      store.touch(realtime_changes_path)
    rescue Gitlab::EtagCaching::Store::InvalidKeyError
      # no-op: not every realtime changes endpoint is using etag caching
    end
  end
end

#in_progress?Boolean

This method is coupled to the repository mirror domain. Use with caution in the importers domain. As an alternative, use the ‘#completed?` method. See EE-override and gitlab.com/gitlab-org/gitlab/-/merge_requests/4697

Returns:

  • (Boolean)


149
150
151
# File 'app/models/project_import_state.rb', line 149

def in_progress?
  scheduled? || started?
end

#mark_as_failed(error_message) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/models/project_import_state.rb', line 127

def mark_as_failed(error_message)
  original_errors = errors.dup
  sanitized_message = sanitized_failure_message(error_message)

  fail_op

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

#realtime_changes_pathObject



116
117
118
119
120
121
# File 'app/models/project_import_state.rb', line 116

def realtime_changes_path
  Gitlab::Routing.url_helpers.polymorphic_path([:realtime_changes_import, project.import_type.to_sym], format: :json)
rescue NoMethodError
  # polymorphic_path throws NoMethodError when no such path exists
  nil
end

#relation_hard_failures(limit:) ⇒ Object



123
124
125
# File 'app/models/project_import_state.rb', line 123

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

#send_completion_notification(notify_group_owners: true) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/models/project_import_state.rb', line 162

def send_completion_notification(notify_group_owners: true)
  return unless project.notify_project_import_complete?

  run_after_commit do
    Projects::ImportExport::ImportCompletionNotificationWorker.perform_async(
      project.id,
      'user_mapping_enabled' => user_mapping_enabled?,
      'notify_group_owners' => notify_group_owners,
      'safe_import_url' => safe_import_url
    )
  end
end

#set_notification_dataObject



175
176
177
178
# File 'app/models/project_import_state.rb', line 175

def set_notification_data
  self.user_mapping_enabled ||= project.import_data&.user_mapping_enabled?
  self.safe_import_url ||= project.safe_import_url(masked: false)
end

#started?Boolean

Returns:

  • (Boolean)


157
158
159
160
# File 'app/models/project_import_state.rb', line 157

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