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
- 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 ‘Project` to import the data into.
-
#importer_class ⇒ Object
Returns the class to use for importing the object.
- #increment_object_counter?(_object) ⇒ Boolean
- #object_type ⇒ Object
-
#perform_failure(project_id, hash, correlation_id) ⇒ Object
hash - A Hash containing the details of the object to import.
-
#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.
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 71 72 73 74 75 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 40 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) # 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 if increment_object_counter?(object) Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :imported) end info(project.id, message: 'importer finished') rescue NoMethodError => e # This exception will be more useful in development when a new # Representation is created but the developer forgot to add a # `:github_identifiers` field. track_and_raise_exception(project, e, fail_import: true) rescue ActiveRecord::RecordInvalid, NotRetriableError => e # We do not raise exception to prevent job retry failure = track_exception(project, e) add_identifiers_to_failure(failure, object.github_identifiers) rescue StandardError => e track_and_raise_exception(project, e) end |
#importer_class ⇒ Object
Returns the class to use for importing the object.
105 106 107 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 105 def importer_class raise NotImplementedError end |
#increment_object_counter?(_object) ⇒ Boolean
90 91 92 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 90 def increment_object_counter?(_object) true end |
#object_type ⇒ Object
94 95 96 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 94 def object_type raise NotImplementedError end |
#perform_failure(project_id, hash, correlation_id) ⇒ Object
hash - A Hash containing the details of the object to import.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 78 def perform_failure(project_id, hash, correlation_id) project = Project.find_by_id(project_id) return unless project failure = project.import_failures.failures_by_correlation_id(correlation_id).first return unless failure object = representation_class.from_json_hash(hash) add_identifiers_to_failure(failure, object.github_identifiers) end |
#representation_class ⇒ Object
Returns the representation class to use for the object. This class must define the class method ‘from_json_hash`.
100 101 102 |
# File 'app/workers/concerns/gitlab/github_import/object_importer.rb', line 100 def representation_class raise NotImplementedError end |