Module: Gitlab::GithubImport::ObjectImporter

Overview

ObjectImporter defines the base behaviour for every Sidekiq worker that imports a single resource such as a note or pull request.

Constant Summary collapse

NotRetriableError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#import(project, client, hash) ⇒ Object

project - An instance of Project to import the data into. client - An instance of Gitlab::GithubImport::Client hash - A Hash containing the details of the object to import.



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
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 37

def import(project, client, hash)
  if project.import_state&.completed?
    info(
      project.id,
      message: 'Project import is no longer running. Stopping worker.',
      import_status: project.import_state.status
    )

    return
  end

  object = representation_class.from_json_hash(hash)

  object.object_type = object_type if object.respond_to?(:object_type=)

  # To better express in the logs what object is being imported.
  self.github_identifiers = object.github_identifiers
  info(project.id, message: 'starting importer')

  importer_class.new(object, project, client).execute

  increment_object_counter(object, project) if increment_object_counter?(object)

  info(project.id, message: 'importer finished')
rescue ActiveRecord::RecordInvalid, NotRetriableError, NoMethodError => e
  # We do not raise exception to prevent job retry
  track_exception(project, e)
rescue UserFinder::FailedToObtainLockError
  warn(project.id, message: 'Failed to obtaing lock for user finder. Retrying later.')

  raise
rescue StandardError => e
  track_and_raise_exception(project, e)
end

#importer_classObject

Returns the class to use for importing the object.

Raises:

  • (NotImplementedError)


91
92
93
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 91

def importer_class
  raise NotImplementedError
end

#increment_object_counter(_object, project) ⇒ Object



76
77
78
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 76

def increment_object_counter(_object, project)
  Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :imported)
end

#increment_object_counter?(_object) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 72

def increment_object_counter?(_object)
  true
end

#object_typeObject

Raises:

  • (NotImplementedError)


80
81
82
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 80

def object_type
  raise NotImplementedError
end

#representation_classObject

Returns the representation class to use for the object. This class must define the class method from_json_hash.

Raises:

  • (NotImplementedError)


86
87
88
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 86

def representation_class
  raise NotImplementedError
end