diff options
Diffstat (limited to 'app/workers/concerns/gitlab/github_import/object_importer.rb')
-rw-r--r-- | app/workers/concerns/gitlab/github_import/object_importer.rb | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/app/workers/concerns/gitlab/github_import/object_importer.rb b/app/workers/concerns/gitlab/github_import/object_importer.rb index 63c1ba8e699..575cd4862b0 100644 --- a/app/workers/concerns/gitlab/github_import/object_importer.rb +++ b/app/workers/concerns/gitlab/github_import/object_importer.rb @@ -15,17 +15,25 @@ module Gitlab feature_category :importers worker_has_external_dependencies! + + def logger + @logger ||= Gitlab::Import::Logger.build + end end # 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. def import(project, client, hash) - object = representation_class.from_json_hash(hash) + info(project.id, message: 'starting importer') + object = representation_class.from_json_hash(hash) importer_class.new(object, project, client).execute counter.increment + info(project.id, message: 'importer finished') + rescue => e + error(project.id, e) end def counter @@ -52,6 +60,35 @@ module Gitlab def counter_description raise NotImplementedError end + + private + + def info(project_id, extra = {}) + logger.info(log_attributes(project_id, extra)) + end + + def error(project_id, exception) + logger.error( + log_attributes( + project_id, + message: 'importer failed', + 'error.message': exception.message + ) + ) + + Gitlab::ErrorTracking.track_and_raise_exception( + exception, + log_attributes(project_id) + ) + end + + def log_attributes(project_id, extra = {}) + extra.merge( + import_source: :github, + project_id: project_id, + importer: importer_class.name + ) + end end end end |