diff options
Diffstat (limited to 'app/workers/concerns/gitlab/github_import/stage_methods.rb')
-rw-r--r-- | app/workers/concerns/gitlab/github_import/stage_methods.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/workers/concerns/gitlab/github_import/stage_methods.rb b/app/workers/concerns/gitlab/github_import/stage_methods.rb index e2dee315cde..e5985fb94da 100644 --- a/app/workers/concerns/gitlab/github_import/stage_methods.rb +++ b/app/workers/concerns/gitlab/github_import/stage_methods.rb @@ -5,11 +5,17 @@ module Gitlab module StageMethods # project_id - The ID of the GitLab project to import the data into. def perform(project_id) + info(project_id, message: 'starting stage') + return unless (project = find_project(project_id)) client = GithubImport.new_client_for(project) try_import(client, project) + + info(project_id, message: 'stage finished') + rescue => e + error(project_id, e) end # client - An instance of Gitlab::GithubImport::Client. @@ -27,6 +33,39 @@ module Gitlab Project.joins_import_state.where(import_state: { status: :started }).find_by(id: id) end # rubocop: enable CodeReuse/ActiveRecord + + 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: 'stage 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, + import_stage: self.class.name + ) + end + + def logger + @logger ||= Gitlab::Import::Logger.build + end end end end |