Module: Gitlab::GithubImport::ObjectImporter
- Extended by:
- ActiveSupport::Concern
- Included in:
- Attachments::ImportIssueWorker, Attachments::ImportMergeRequestWorker, Attachments::ImportNoteWorker, Attachments::ImportReleaseWorker, ImportCollaboratorWorker, ImportDiffNoteWorker, ImportIssueEventWorker, ImportIssueWorker, ImportLfsObjectWorker, ImportNoteWorker, ImportProtectedBranchWorker, ImportPullRequestWorker, PullRequests::ImportMergedByWorker, PullRequests::ImportReviewRequestWorker, PullRequests::ImportReviewWorker, ReplayEventsWorker
- Defined in:
- app/workers/concerns/gitlab/github_import/object_importer.rb
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
-
#import(project, client, hash) ⇒ Object
project - An instance of
Projectto import the data into. -
#importer_class ⇒ Object
Returns the class to use for importing the object.
- #increment_object_counter(_object, project) ⇒ Object
- #increment_object_counter?(_object) ⇒ Boolean
- #object_type ⇒ Object
-
#representation_class ⇒ Object
Returns the representation class to use for the object.
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_class ⇒ Object
Returns the class to use for importing the object.
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
72 73 74 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 72 def increment_object_counter?(_object) true end |
#object_type ⇒ Object
80 81 82 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 80 def object_type raise NotImplementedError end |
#representation_class ⇒ Object
Returns the representation class to use for the object. This class must define the class method from_json_hash.
86 87 88 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 86 def representation_class raise NotImplementedError end |